HTTP Verbs Flashcards

1
Q

HTTP GET

A

Use GET requests to retrieve resource representation/information only – and not modify it in any way

Additionally, GET APIs should be idempotent. Making multiple identical requests must produce the same result every time until another API (POST or PUT) has changed the state of the resource on the server.

Examples
HTTP GET http://www.appdomain.com/users
HTTP GET http://www.appdomain.com/users?size=20&page=5
HTTP GET http://www.appdomain.com/users/123
HTTP GET http://www.appdomain.com/users/123/address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

HTTP GET Response Codes

A

If the resource is found on the server, then it must return HTTP response code 200 (OK) – along with the response body, which is usually either XML or JSON content (due to their platform-independent nature)

In case the resource is NOT found on the server then API must return HTTP response code 404 (NOT FOUND).

Similarly, if it is determined that the GET request itself is not correctly formed then the server will return the HTTP response code 400 (BAD REQUEST).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

HTTP Post

A

When talking strictly about REST, POST methods are used to create a new resource into the collection of resources.
Use POST APIs to create new subordinate resources, e.g., a file is subordinate to a directory containing it or a row is subordinate to a database table.
Please note that POST is neither safe nor idempotent, and invoking two identical POST requests will result in two different resources containing the same information (except resource ids)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

HTTP Post Response Code

A

Many times, the action performed by the POST method might not result in a resource that can be identified by a URI. In this case, either HTTP response code 200 (OK) or 204 (No Content) is the appropriate response status.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

HTTP Post Examples

A

HTTP POST http://www.appdomain.com/users
HTTP POST http://www.appdomain.com/users/123/accounts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

HTTP Put

A

Use PUT APIs primarily to update an existing resource (if the resource does not exist, then API may decide to create a new resource or not).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

HTTP Put vs Post

A

The difference between the POST and PUT APIs can be observed in request URIs. POST requests are made on resource collections, whereas PUT requests are made on a single resource.

HTTP PUT http://www.appdomain.com/users/123
HTTP PUT http://www.appdomain.com/users/123/accounts/456

HTTP POST http://www.appdomain.com/users
HTTP POST http://www.appdomain.com/users/123/accounts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

HTTP Put Response Codes

A

If a new resource has been created by the PUT API, the origin server MUST inform the user agent via the HTTP response code 201 (Created) response.

If an existing resource is modified, either the 200 (OK) or 204 (No Content) response codes SHOULD be sent to indicate successful completion of the request.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

HTTP Delete

A

As the name applies, DELETE APIs delete the resources (identified by the Request-URI).

DELETE operations are idempotent. If you DELETE a resource, it’s removed from the collection of resources.

Some may argue that it makes the DELETE method non-idempotent. It’s a matter of discussion and personal opinion.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

HTTP Delete Response Codes

A

A successful response of DELETE requests SHOULD be an HTTP response code 200 (OK) if the response includes an entity describing the status.
The status should be 202 (Accepted) if the action has been queued.
The status should be 204 (No Content) if the action has been performed but the response does not include an entity.
Repeatedly calling DELETE API on that resource will not change the outcome – however, calling DELETE on a resource a second time will return a 404 (NOT FOUND) since it was already removed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

HTTP DELETE Example

A

HTTP DELETE http://www.appdomain.com/users/123
HTTP DELETE http://www.appdomain.com/users/123/accounts/456

How well did you know this?
1
Not at all
2
3
4
5
Perfectly