| Parameters | Description |
|---|---|
| none | returns all todos |
complete=? |
returns all todos that are completed or not |
order_by=?[direction=asc|desc] |
sort items by a property of the todo, optionally in ascending or descending order |
id=? |
returns the todo with the given id |
| Parameters | Description |
|---|---|
content=?[&priority=?][&due_date=?] |
create a new todo |
id=?&action=update&content=?[&priority=?][&due_date=?] |
update a todo |
id=?&action=delete |
delete a todo |
id=?&action=complete[&state=true|false] |
mark a todo as completed or remove the completed status |
See more detailed instructions below
Each todo is represented as an object that has several properties
| property | type | description |
|---|---|---|
| content | string | title or content of the todo |
| id | number | this will be unique for each item |
| created_at | Date | automatically generated date |
| priority | number | must be an integer >= 0 |
| due_date | Date | optional |
| completed | Date | date completed, defaults to null |
Used for retrieving data
- a get with no parameters will return all the todos
- sending the parameter
completewith a value oftrueorfalsewill give all todo items that are completed or not, respectively - sending the parameter
idwith a value of a todo item's id will return just that one todo item - sending the parameter
order_bywith a value of one of the todo item's properties will sort the results by that property- you can also send a
directionparameter for the direction of the sort that takes valuesascordesc - defaults to ascending order if no
directionis passed
- you can also send a
Used for creating and modifying data
Creating a Record
Sending only content, priority, and due_date parameters will create a new todo item, content is required, priority will default to 0, and due_date will default to null if nothing is passed.
The server's response will be the object that was newly created or an error message if something went wrong.
Modifying a Record
To modify a record you must pass two parameters:
id, the id of the record to be modifiedactionone ofupdate,delete, orcompleteupdate: will also take three additional parameters,content, which is required,priorityanddue_dateare optional. All properties will be updated accordingly.delete: as the name implies will delete the todo itemcomplete: optionally takes astateparameter with valuestrueorfalse- if no
stateparameter is passed, or ifstateis set totrue, thecompletedproperty of the todo will be set to the time when the server receives your ajax request - if
stateis set tofalse, thecompleteproperty of the todo will be set tonull
- if no
The server's response will be the object that was modified, or an error message if something went wrong.
Update a todo's information
$.post('/todo-json.php',{
"id": 3,
"action": "update",
"content": "updated todo item"
});Get all completed todos and sort them by descending priority
$.ajax({
"url": "/todo-json.php",
"type": "GET",
"data": {
"complete": "true",
"order_by": "priority",
"direction": "desc"
}
});
Great documentation! It's missing the $GET parameters for sorting and setting the sort direction though.