REST is an architectural style for building distributed systems based on HTTP. It uses HTTP verbs like GET, POST, PUT, DELETE to transfer a representation of resources between client and server. Resources are nouns that can be XML, JSON or plain text representations of real-world objects. Best practices for REST include using plural nouns for endpoints, including an API version, using HTTP verbs on endpoints, and returning appropriate HTTP response codes.
3. What REST is Not
• REST is not HTTP
• REST is not a protocol
4. What REST Is
• Representational StateTransfer
• An architectural style
• Transfers a representation of the current state of a logical resource
• Resource can be XML, JSON, or plain text
• Stateless server
8. Best Practices – URI Endpoints
• Resources acted on by HTTP verb methods
• Send HTTP requests to endpoints; Uniform Resource Identifiers
• An endpoint will listen for a specific HTTP request
/api/v1/products
myAPI.com/api/v1/products
9. Best Practices – URI Endpoints
• /api/v1/products
• Not a verb (/getAllProducts or /deleteProduct)
• Endpoints should be plural
• Should include version
10. Best Practices – HTTP Verb Methods
• GET /api/v1/products
• GET /api/v1/products/36
• POST /api/v1/products
• PUT /api/v1/products/42
• PUT /api/v1/products
• DELETE /api/v1/products/19
• DELETE /api/v1/products
11. Best Practices – Sub Resource Relationships
• /api/v1/users/367/posts
• /api/v1/users/367/posts/23/comments
• /api/v1/users?name=sam
12. Best Practices – Response Codes
• 200 – successful request
• 201 – successfully created,
• 400 – bad request
• 401 – unauthorized
• 403 – forbidden
• 404 – not found
• 500 – internal server error
• 418 – I’m a teapot