Advanced Microservices: thomashunter.name/ms
POST /v1/animal HTTP/1.1\n <-- Request Line Host: api.example.org\n <-- Request Headers Accept: application/json\n Content-Type: application/json\n Content-Length: 24\n \n <-- Two Newlines {\n <-- Body "name": "Gir",\n "animal_type": "12"\n }\n
/collection
/collection/{resource_id}
/collection/{resource_id}/sub
/collection/{resource_id}/sub/{id}
GET /collection?filters
GET /collection/{resource_id}?fields
POST /collection
DELETE /collection/{resource_id}
PUT /collection/{resource_id}
PATCH /collection/{resource_id}
HEAD /endpoint
OPTIONS /endpoint
Accept
: Content Types the client acceptsAccept-Language
: Language expected by clientContent-Length
: Length of request bodyContent-Type
: Type of data if a body is presentHost
: For virtual hosting, usually ignored by appUser-Agent
: Information about clientHTTP/1.1 200 OK\n <-- Status Line Date: Wed, 14 Jun 2017 23:23:01 GMT\n <-- Response Headers Content-Type: application/json\n Access-Control-Max-Age: 1728000\n Cache-Control: no-cache\n \n <-- Two Newlines {\n <-- Body "id": "12",\n "created": "2017-06-14T23:22:59Z",\n "modified": null,\n "name": "Gir",\n "animal_type": "12"\n }\n
101 Switching Protocols
200 OK
201 Created
202 Accepted
(e.g. asynchronous creation)204 No Content
301 Moved Permanently
302 Found
307 Temporary Redirect
308 Permanent Redirect
400 Invalid Request
401 Unauthorized
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
500 Internal Server Error
501 Not Implemented
503 Service Unavailable
(e.g. no database)521 Web Server Is Down
Cache-Control
: Cache policy, e.g. no-cache
Content-Language
: E.g. en-US
Content-Length
: Response body length in bytesContent-Type
: E.g. application/json
Date
: Date and time on the serverExpires
: Time when content should expireServer
: Useless field for bragging{
"strings": "value",
"numbers": 12,
"moreNumbers": -0.1,
"booleans": true,
"nullable": null,
"array": [1, "abc", false],
"object": { "very": "deep" }
}
snake_case
: The most bytesPascalCase
: The most shiftscamelCase
: Happy mediumenabled
instead of disabled
public
instead of private
is_cool
or cool_flag
, just cool
"2017-06-15T04:23:46+00:00"
"2017-06-15T04:23:46Z"
"2017-06-15T04:23:46.987Z"
1493268311123
https://api.example.org/v1/*
Accept: application/json+v1
X-Api-Version: 1
{
"error": "database_connection_failed",
"error_human": "Unable to establish database connection",
"data": null
}
{
"error": null,
"error_human": null,
"data": [{"id": "11"}, {"id": "12"}],
"offset": 10,
"per_page": 10
}
{
"data": [{
"type": "articles", "id": "1",
"attributes": {
"title": "Article Title", "body": "Content"
},
"relationships": {
"author": { "data": {"id": "42", "type": "people"} }
}
}],
"included": [{
"type": "people", "id": "42",
"attributes": { "name": "John", "age": 80 }
}]
}
{
user(id: "tlhunter") {
id
name
photo {
id
url
}
friends {
id
name
}
}
}
{
"data": {
"user": {
"name": "Thomas Hunter II",
"id": "tlhunter",
"photo": { "id": "12", "url": "http://im.io/12.jpg" },
"friends": [
{ "name": "Rupert Styx", "id": "rupertstyx" }
]
}
}
}
{
"id": "tlhunter",
"xyz": [1,2,3]
}
82 a2 69 64 a8 74 6c 68 75 6e 74 65 72 a3 78 79 7a 93 01 02 03
{"jsonrpc":"2.0","method":"subtract","params":[42,23],"id":1}
{"jsonrpc": "2.0", "result": 19, "id": 1}