Метод | Путь | Действие |
---|---|---|
GET | /createArticle | Создать статью |
GET | /articlesList | Получить список статей |
GET | /articles/getById?id=1 | Получить статью |
GET | /articles/update?newTitle=Заголовок | Обновить статью |
LOL | /deleteArticle?id=1 | Удалить статью |
Метод | Путь | Действие |
---|---|---|
POST | /articles | Создать статью |
GET | /articles | Получить список статей |
GET | /articles/1 | Получить статью |
PATCH | /articles/1 | Обновить статью |
DELETE | /articles/1 | Удалить статью |
DELETE /articles/1 HTTP/1.1
Accept: application/json
HTTP/1.1 200 OK
Content-Type: application/json
<ПУСТАЯ СТРОКА>
POST /articles HTTP/1.1
Content-Type: application/json
{ "id": 1, "title": "Про JSON:API"}
HTTP/1.1 422 Unprocessable Entity
HTTP/1.1 403 Forbidden
HTTP/1.1 500 Internal Server Error
HTTP/1.1 422 Unprocessable Entity
Content-Type: application/json
{ "errors": [{
"status": "422",
"title": "Title already exist",
}]}
GET /articles HTTP/1.1
Content-Type: application/json
HTTP/1.1 200 OK
[
{ "id": 1, "title": "Про JSON:API"},
{ "id": 2, "title": "Про XML-RPC"}
]
GET /articles?page[size]=30&page[number]=2
Content-Type: application/json
HTTP/1.1 200 OK
{
"data": [{ "id": 1, "title": "JSON:API"}, ...],
"meta": { "count": 10080 }
}
GET /articles?page[offset]=30&page[limit]=30
Content-Type: application/json
HTTP/1.1 200 OK
{
"data": [{ "id": 1, "title": "JSON:API"}, ...],
"meta": { "count": 10080 }
}
GET /articles?page[published_at]=1538332156
Content-Type: application/json
HTTP/1.1 200 OK
{
"data": [{ "id": 1, "title": "JSON:API"}, ...],
"meta": { "count": 10080 }
}
Выведем 10 статей с указанием автора
Итого: 11 запросов
GET /articles?include=author
Content-Type: application/json
HTTP/1.1 200 OK
{ "data": [{
{ attributes: { "id": 1, "title": "JSON:API" },
{ relationships: {
"author": { "id": 1, "name": "Avdeev" } }
}, ...
}]}
GET /articles?include=author HTTP/1.1
GET /articles?include=author,image HTTP/1.1
GET /articles?include=author,author.avatar HTTP/1.1
Выведем 10 статей с указанием автора, у всех статей один автор
Итого: один автор включен в ответ 10 раз
HTTP/1.1 200 OK
{ "data": [{
"id": "1", "type": "article",
"attributes": { "title": "JSON:API" },
"relationships": { ... }
}, ... ]
}
HTTP/1.1 200 OK
{ "data": [{
...
"relationships": {
"author": { "id": 1, "type": "people" } }
}
}, ... ]
}
HTTP/1.1 200 OK
{
"data": [ ... ],
"included": [{
"id": 1, "type": "people",
"attributes": { "name": "Avdeev" }
}]
}
GET /articles?fields[article]=title HTTP/1.1
HTTP/1.1 200 OK
{ "data": [{
"id": "1", "type": "article",
"attributes": { "title": "Про JSON:API" },
}, ... ]
}
GET /articles?filters[search]=api HTTP/1.1
GET /articles?filters[from_date]=1538332156 HTTP/1.1
GET /articles?filters[is_published]=true HTTP/1.1
GET /articles?filters[author]=1 HTTP/1.1
GET /articles?sort=title HTTP/1.1
GET /articles?sort=published_at HTTP/1.1
GET /articles?sort=-published_at HTTP/1.1
GET /articles?sort=author,-published_at HTTP/1.1
GET /articles HTTP/1.1
{
"data": [{
...
"links": { "self": "http://localhost/articles/1" },
"relationships": { ... }
}],
"links": { "self": "http://localhost/articles" }
}
...
"relationships": {
"comments": {
"links": {
"self": "http://localhost/articles/1/relationships/comments",
"related": "http://localhost/articles/1/comments"
}
}
}
Список реализаций спефикации — https://jsonapi.org/implementations/
GET /articles/1?include=comments HTTP/1.1
...
"relationships": {
"comments": {
"data": [0 ... ∞]
}
}
GET /comments?filters[article]=1&page[size]=30 HTTP/1.1
{
"data": [0 ... 29]
}
GET /articles/1?include=comments HTTP/1.1
GET /articles/1/comments HTTP/1.1
GET /comments?filters[article]=1 HTTP/1.1
GET /comments?include=commentable HTTP/1.1
...
"relationships": {
"commentable": {
"data": { "type": "article", "id": "1" }
}
}
GET /users?include=users_comments HTTP/1.1
...
"relationships": {
"users_comments": {
"data": [{ "type": "users_comments", "id": "1" }, ...]
},
}
GET http://services.odata.org/v4/TripRW/People HTTP/1.1
OData-Version: 4.0
OData-MaxVersion: 4.0
HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
{
'@odata.context': 'http://services.odata.org/V4/...
'@odata.nextLink': 'http://services.odata.org/V4/...
'value': [{
'@odata.etag': 'W/'08D1D5BD423E5158'',
'UserName': 'russellwhyte',
...