[API] Items
GET /items
Returns all items as an array.
Parameters
s: [optional] Searchstring. If provided, returns only those items whose name match the search term.
Response
200 All found
items.
500 A server error occured.
Example
Request:
curl http://localhost:8082/api/v1/items
Result:
[
{
"id": 1,
"title": "Cheese",
"price": 9.99,
"description": "",
"other": "",
"created": 0,
"updated": 1512551324,
"quantity": 4
},
{
"id": 3,
"title": "Something",
"price": 9.99,
"description": "Lorem Ipsum dolor sit amet",
"other": "",
"created": 1511947156,
"updated": 1511947156,
"quantity": 24
},
{
"id": 7,
"title": "Some other thing",
"price": 99.99,
"description": "",
"other": "",
"created": 1511963266,
"updated": 1511963266,
"quantity": 15
}
]
GET /items/:id
Returns a JSON-Object with all informations about a single item.
Parameters
id: The ID
of the item you want to retrieve.
Response
200 The item.
400 ID
is invalid or empty.
404 The item does not exist.
500 A server error occured.
PUT /items
🔒
Creates a new item.
Payload
Expects a JSON item object. Either directly as a JSON-object see the example below
or as a string via the form value item
. When sending as JSON, you need to include the Content-Type: application/json;charset=utf-8
-Header.
Response
200 The item was successfully inserted. Returns the newly created item.
400 No item payload was provided or the title is empty. Returns a more specific message.
500 A server error occured.
Example
Request:
curl \
-H 'Authorization: Bearer <YOUR TOKEN HERE>' \
-X PUT \
-d item='{"title": "Ham","price": 11.3,"description": "Very pricy, very good","quantity": 87}' \
http://localhost:8082/api/v1/items
Response:
{
"id": 11,
"title": "Ham",
"price": 11.3,
"description": "Very pricy, very good",
"other": "",
"created": 1512655990,
"updated": 1512655990,
"quantity": 87
}
DELETE /items/:id
🔒
Deletes a item by its ID
.
Parameters
ID: The ID
of the item you want to delete.
Response
200 The item was successfully deleted.
400 ID
is invalid or empty.
404 No book with this ID
exists.
500 An error occured while deleting.
Example
Request:
curl \
-H 'Authorization: Bearer <YOUR TOKEN HERE>' \
-X DELETE \
http://localhost:8082/api/v1/items/11
Response:
{"message":"success"}
POST /items/:id
🔒
Updates an item by its ID
. Returns the newly updated item.
Parameters
ID: The ID
of the item you want to update.
Payload
Expects a JSON item object see inserting an item
.
You need to provide a quantity, otherwise the quantity is set to 0! This is because the send JSON values are interpreted into an object to be able to deal with it internally. Any not-given value is interpreted to its standard
`""` for strings, `0` for integers
.
Response
200 The item was successfully updated.
400 Publisher payload is empty, not valid or ID
is invalid.
404 No publisher with this ID
exists
500 An error occured while updating.
Example
Request:
curl \
-H 'Authorization: Bearer <YOUR TOKEN HERE>' \
-X POST \
-d item='{"title": "Lorem Impsum"}' \
http://localhost:8082/api/v1/items/11
Response:
{
"id": 11,
"title": "Lorem Ipsum",
"price": 11.3,
"description": "Very pricy, very good",
"other": "",
"created": 1512656045,
"updated": 1512656177,
"quantity": 0
}