Example requests
These requests have been generated against the "GettingStarted" application and are updated on every deployment.
All of these requests have been created using out-of-the-box features.
Note
curl requires "[" and "]" in URLs to be escaped.
Reading data
Get all
#Requires -Version 7.3
curl -s -f http://localhost:14141/api/books
{
"links": {
"self": "/api/books",
"first": "/api/books",
"last": "/api/books"
},
"data": [
{
"type": "books",
"id": "1",
"attributes": {
"title": "Frankenstein",
"publishYear": 1818
},
"relationships": {
"author": {
"links": {
"self": "/api/books/1/relationships/author",
"related": "/api/books/1/author"
}
}
},
"links": {
"self": "/api/books/1"
}
},
{
"type": "books",
"id": "2",
"attributes": {
"title": "Robinson Crusoe",
"publishYear": 1719
},
"relationships": {
"author": {
"links": {
"self": "/api/books/2/relationships/author",
"related": "/api/books/2/author"
}
}
},
"links": {
"self": "/api/books/2"
}
},
{
"type": "books",
"id": "3",
"attributes": {
"title": "Gulliver's Travels",
"publishYear": 1726
},
"relationships": {
"author": {
"links": {
"self": "/api/books/3/relationships/author",
"related": "/api/books/3/author"
}
}
},
"links": {
"self": "/api/books/3"
}
}
],
"meta": {
"total": 3
}
}
Get by ID
#Requires -Version 7.3
curl -s -f http://localhost:14141/api/people/1
{
"links": {
"self": "/api/people/1"
},
"data": {
"type": "people",
"id": "1",
"attributes": {
"name": "Mary Shelley"
},
"relationships": {
"books": {
"links": {
"self": "/api/people/1/relationships/books",
"related": "/api/people/1/books"
}
}
},
"links": {
"self": "/api/people/1"
}
}
}
Get with relationship
#Requires -Version 7.3
curl -s -f http://localhost:14141/api/books?include=author
{
"links": {
"self": "/api/books?include=author",
"first": "/api/books?include=author",
"last": "/api/books?include=author"
},
"data": [
{
"type": "books",
"id": "1",
"attributes": {
"title": "Frankenstein",
"publishYear": 1818
},
"relationships": {
"author": {
"links": {
"self": "/api/books/1/relationships/author",
"related": "/api/books/1/author"
},
"data": {
"type": "people",
"id": "1"
}
}
},
"links": {
"self": "/api/books/1"
}
},
{
"type": "books",
"id": "2",
"attributes": {
"title": "Robinson Crusoe",
"publishYear": 1719
},
"relationships": {
"author": {
"links": {
"self": "/api/books/2/relationships/author",
"related": "/api/books/2/author"
},
"data": {
"type": "people",
"id": "2"
}
}
},
"links": {
"self": "/api/books/2"
}
},
{
"type": "books",
"id": "3",
"attributes": {
"title": "Gulliver's Travels",
"publishYear": 1726
},
"relationships": {
"author": {
"links": {
"self": "/api/books/3/relationships/author",
"related": "/api/books/3/author"
},
"data": {
"type": "people",
"id": "3"
}
}
},
"links": {
"self": "/api/books/3"
}
}
],
"included": [
{
"type": "people",
"id": "1",
"attributes": {
"name": "Mary Shelley"
},
"relationships": {
"books": {
"links": {
"self": "/api/people/1/relationships/books",
"related": "/api/people/1/books"
}
}
},
"links": {
"self": "/api/people/1"
}
},
{
"type": "people",
"id": "2",
"attributes": {
"name": "Daniel Defoe"
},
"relationships": {
"books": {
"links": {
"self": "/api/people/2/relationships/books",
"related": "/api/people/2/books"
}
}
},
"links": {
"self": "/api/people/2"
}
},
{
"type": "people",
"id": "3",
"attributes": {
"name": "Jonathan Swift"
},
"relationships": {
"books": {
"links": {
"self": "/api/people/3/relationships/books",
"related": "/api/people/3/books"
}
}
},
"links": {
"self": "/api/people/3"
}
}
],
"meta": {
"total": 3
}
}
Get sparse fieldset
#Requires -Version 7.3
curl -s -f http://localhost:14141/api/books?fields%5Bbooks%5D=publishYear
{
"links": {
"self": "/api/books?fields%5Bbooks%5D=publishYear",
"first": "/api/books?fields%5Bbooks%5D=publishYear",
"last": "/api/books?fields%5Bbooks%5D=publishYear"
},
"data": [
{
"type": "books",
"id": "1",
"attributes": {
"publishYear": 1818
},
"links": {
"self": "/api/books/1"
}
},
{
"type": "books",
"id": "2",
"attributes": {
"publishYear": 1719
},
"links": {
"self": "/api/books/2"
}
},
{
"type": "books",
"id": "3",
"attributes": {
"publishYear": 1726
},
"links": {
"self": "/api/books/3"
}
}
],
"meta": {
"total": 3
}
}
Filter on partial match
#Requires -Version 7.3
curl -s -f "http://localhost:14141/api/people?filter=contains(name,'Shell')"
{
"links": {
"self": "/api/people?filter=contains(name,'Shell')",
"first": "/api/people?filter=contains(name,%27Shell%27)",
"last": "/api/people?filter=contains(name,%27Shell%27)"
},
"data": [
{
"type": "people",
"id": "1",
"attributes": {
"name": "Mary Shelley"
},
"relationships": {
"books": {
"links": {
"self": "/api/people/1/relationships/books",
"related": "/api/people/1/books"
}
}
},
"links": {
"self": "/api/people/1"
}
}
],
"meta": {
"total": 1
}
}
Sorting
#Requires -Version 7.3
curl -s -f http://localhost:14141/api/books?sort=-publishYear
{
"links": {
"self": "/api/books?sort=-publishYear",
"first": "/api/books?sort=-publishYear",
"last": "/api/books?sort=-publishYear"
},
"data": [
{
"type": "books",
"id": "1",
"attributes": {
"title": "Frankenstein",
"publishYear": 1818
},
"relationships": {
"author": {
"links": {
"self": "/api/books/1/relationships/author",
"related": "/api/books/1/author"
}
}
},
"links": {
"self": "/api/books/1"
}
},
{
"type": "books",
"id": "3",
"attributes": {
"title": "Gulliver's Travels",
"publishYear": 1726
},
"relationships": {
"author": {
"links": {
"self": "/api/books/3/relationships/author",
"related": "/api/books/3/author"
}
}
},
"links": {
"self": "/api/books/3"
}
},
{
"type": "books",
"id": "2",
"attributes": {
"title": "Robinson Crusoe",
"publishYear": 1719
},
"relationships": {
"author": {
"links": {
"self": "/api/books/2/relationships/author",
"related": "/api/books/2/author"
}
}
},
"links": {
"self": "/api/books/2"
}
}
],
"meta": {
"total": 3
}
}
Pagination
#Requires -Version 7.3
curl -s -f "http://localhost:14141/api/books?page%5Bsize%5D=1&page%5Bnumber%5D=2"
{
"links": {
"self": "/api/books?page%5Bsize%5D=1&page%5Bnumber%5D=2",
"first": "/api/books?page%5Bsize%5D=1",
"last": "/api/books?page%5Bsize%5D=1&page%5Bnumber%5D=3",
"prev": "/api/books?page%5Bsize%5D=1",
"next": "/api/books?page%5Bsize%5D=1&page%5Bnumber%5D=3"
},
"data": [
{
"type": "books",
"id": "2",
"attributes": {
"title": "Robinson Crusoe",
"publishYear": 1719
},
"relationships": {
"author": {
"links": {
"self": "/api/books/2/relationships/author",
"related": "/api/books/2/author"
}
}
},
"links": {
"self": "/api/books/2"
}
}
],
"meta": {
"total": 3
}
}
Writing data
Create resource
#Requires -Version 7.3
curl -s -f http://localhost:14141/api/people `
-H "Content-Type: application/vnd.api+json" `
-d '{
"data": {
"type": "people",
"attributes": {
"name": "Alice"
}
}
}'
{
"links": {
"self": "/api/people"
},
"data": {
"type": "people",
"id": "4",
"attributes": {
"name": "Alice"
},
"relationships": {
"books": {
"links": {
"self": "/api/people/4/relationships/books",
"related": "/api/people/4/books"
}
}
},
"links": {
"self": "/api/people/4"
}
}
}
Create resource with relationship
#Requires -Version 7.3
curl -s -f http://localhost:14141/api/books `
-H "Content-Type: application/vnd.api+json" `
-d '{
"data": {
"type": "books",
"attributes": {
"title": "Valperga",
"publishYear": 1823
},
"relationships": {
"author": {
"data": {
"type": "people",
"id": "1"
}
}
}
}
}'
{
"links": {
"self": "/api/books"
},
"data": {
"type": "books",
"id": "4",
"attributes": {
"title": "Valperga",
"publishYear": 1823
},
"relationships": {
"author": {
"links": {
"self": "/api/books/4/relationships/author",
"related": "/api/books/4/author"
}
}
},
"links": {
"self": "/api/books/4"
}
}
}
Update resource
#Requires -Version 7.3
curl -s -f http://localhost:14141/api/books/1 `
-H "Content-Type: application/vnd.api+json" `
-X PATCH `
-d '{
"data": {
"type": "books",
"id": "1",
"attributes": {
"publishYear": 1820
}
}
}'
Delete resource
#Requires -Version 7.3
curl -s -f http://localhost:14141/api/books/1 `
-X DELETE