Created by Sebastian Müller / sebastian.mueller@red6-es.de / @red6_es
A resource is similar to an object/document instance.
| HTTP method | Description |
|---|---|
| GET | Retrieves a list of resources or a specific resource. |
| PUT / PATCH | Updates a resource |
| POST | Creates a new resources |
| DELETE | Deletes a resource. |
GET /resources - Retrieves a list of
resources
GET /resources/{id} - Retrieves a specific
resource by ID
PUT /resources/{id} - Updates resource by ID
PATCH /resources/{id} - Partially updates
resource by ID
POST /resources - Creates a new resource
DELETE /resources/{id} - Deletes resource by
ID
200 OK – [GET]
201 CREATED – [POST/PUT/PATCH]
204 NO CONTENT – [DELETE]
400 INVALID REQUEST – [POST/PUT/PATCH]
404 NOT FOUND – [*]
500 INTERNAL SERVER ERROR – [*]
GET /persons/12345 HTTP/1.1
Host: pdb.hanse
Content-Type: application/json; charset=utf-8
{
"id": "12345",
"firstName": "Max",
"lastName": "Mustermann"
}
GET /persons/12345/addresses HTTP/1.1
Host: pdb.hanse
Content-Type: application/json; charset=utf-8
[{
"id": "67890",
"street": "Siegfried-Wedells-Platz",
"number": "1",
"city": "Hamburg",
"zip": "20354"
}]
An example from GitHub's gist API:
PUT /gist/{id}/star - Star a gist
DELETE /gist/{id}/star - Unstar a gist
Query parameters are for like filtiering or sorting.
GET /persons?state=inactive - Retrieves a
list of inactive persons
GET /persons?sort=-priority - Retrieves a
list of persons in descending order of priority
For example, the recently updated persons query could be packaged up as:
GET /persons/recently_updated
curl https://example.com/resources \
-H "Accept: application/xml"
Use URI and header together.
curl https://example.com/v1/resources
curl https://example.com/resources \
-H "Version: v1"
curl https://example.com/v1/resources \
-H "Version: 2015-06-02"
The URI has a major version and the header has date based sub-versions.
Always use SSL. No exceptions.
NO cookies or sessions