Building the API
A pure REST approach may use all of the HTTP methods detailed in the following table:
HTTP Verb |
Sample URI |
Task performed |
---|---|---|
GET |
|
Retrieves the city with ID 10 |
DELETE |
|
Deletes the city with ID 10 |
POST |
|
Creates a new city |
PUT |
|
Updates the city with ID 10 |
PATCH |
|
Performs a partial update to the city with ID 10 |
OPTIONS |
|
Returns all the available operations on the city with ID 10 |
HEAD |
|
Returns only the HTTP headers |
However, in order to enforce compatibility with old clients of the platform with a restricted set of available HTTP options, we can also choose to be pragmatic and perform every operation with a single verb using HTTP headers to specify the operation, as follows:
POST http://api.cloudmakers.xyz/geo HTTP/1.1 Accept: application/json x-cm-operation: PUT
This method requires an adapter at the API endpoint in order to provide routing to the appropriate operation type.
This...