Writing Beautiful
RESTful APIs
Ethan Ballinger
All About REST – Part 2
Writing Beautiful RESTful APIs
All About REST – Part 2
• Operations
• Status Codes
Writing Beautiful RESTful APIs…All About REST – Part 2
Operations - GET
• Used to retrieve information
• Does not take in a request body (payload)
• Method is considered "safe" as it cannot change the state of the
resource
• Typically used to get an individual item or a collection of items
Writing Beautiful RESTful APIs…All About REST – Part 2
Operations - POST
• Used to have the server accept the enclosed entity and include it
as part of the requested resource
• Does take in a request body (typically)
• Method is not considered "safe" as it can change the state of the
resource
• Typically used to create a new item under a particular resource
Writing Beautiful RESTful APIs…All About REST – Part 2
Operations - PUT
• Used to have the server accept the enclosed entity and store it
under the resource
• Does take in a request body (typically)
• Method is not considered "safe" as it can change the state of the
resource
• Typically is used to replace an existing item under a particular
resource
Writing Beautiful RESTful APIs…All About REST – Part 2
Operations - PATCH
• Used to apply partial updates to a resource
• Does take in a request body (typically)
• Method is not considered "safe" as it can change the state of the
resource
• Typically is used to update part of an existing item under a
particular resource
Writing Beautiful RESTful APIs…All About REST – Part 2
Operations - DELETE
• Used to delete a particular resource
• Does not take in a request body
• Method is not considered "safe" as it can change the state of the
resource
• Typically is used to delete or remove a particular resource
Writing Beautiful RESTful APIs…All About REST – Part 2
Operations - OPTIONS
• Used to return the various operations a server supports for the
provided URL
• Does not take in a request body
• Method is considered "safe" as it cannot change the state of the
resource
• Typically used to by browsers to negotiate with the server to
determine what types of operations they support
Writing Beautiful RESTful APIs…All About REST – Part 2
Status Codes
100 Level: Informational
200 Level: Success
• 200 (OK) - The request was successful
• 201 (Created) - The request was successful and has resulted in a
new resource being created
• 204 (No Content) - The request was successful, but the server
has not returned any information
300 Level: Redirection
• 304 (Not Modified) - Tells the client, that the value it has for the
resource has not changed and still matches what they client has
Writing Beautiful RESTful APIs…All About REST – Part 2
Status Codes (cont.)
400 Level: Client Failure
• 400 (Bad Request) - The server cannot understand the request
due to bad syntax
• 401 (Unauthorized) - The request requires user authentication
and it was not provided
• 403 (Forbidden) - The server received the request, but it is not
willing to fulfill it
• 404 (Not Found) - The requested resource does not exist or
could not be located by the server
• 409 (Conflict) - The request could not be completed due to a
conflict with the state of the resource
500 Level: Server Failure
• 500 (Internal Server Error) - The server encountered an
unexpected error and could not complete the request