1 / 11

Rest Best Practices

REST, or REpresentational State Transfer, is an architectural style for providing standards between computer systems on the web, making it easier for systems to communicate with each other. Comprised of the best practices for creating REST endpoints.

only2dray
Download Presentation

Rest Best Practices

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. REST REST, or REpresentational State Transfer, is an architectural style for providing standards between computer systems on the web, making it easier for systems to communicate with each other. We use REST primarily as a way to communicate between computer systems on the World Wide Web with JSON.

  2. REST vs HTTP • REST is an architectural style and not the standard. • HTTP is a protocol to transfer hyper-text. • Provides a lot of freedom to implement various design best practices. • Flexibility to use some other application protocol with REST • GET, POST, PUT, DELETE • GET is meant to perform read a resource. • POST is used to create a new resource. • PUT is used to update an existing resource. • DELETE is for deleting an existing resource.

  3. HATEOAS • Hypermedia As The Engine Of Application State • Provide specific response for a request and hypermedia links to related endpoints and thus decouple the design

  4. HATEOS Sample

  5. RESTful API • Works on client-server architecture • Does not maintain states between two consecutive request. • Provides flexibility, scalability over distributed system • Concrete is better than Abstract • Here is an example of creating REST endpoints with Spring - https://www.devglan.com/spring-boot/spring-boot-angular-example

  6. URI Formatting • Resources are Nouns, Not Verbs • HTTP methods are verbs • Singular vs Plural • /getAllUsers • /updateUser/{userId} • /updateUserArticle/{articleId}

  7. Error Handling • Maintain uniformity • Should include message, status_code, type • An Example - https://www.devglan.com/spring-security/exception-handling-in-spring-security

  8. Status Codes • 1XX – Informational Communicates transfer protocol-level information. • 2XX – Success Indicates that the client’s request was accepted successfully. • 3XX – Redirection Indicates that the client must take some additional action in order to complete their request. • 4XX - Client Error • 5XX – Server Error

  9. Security • Some useful resource to secure REST endpoints. https://www.devglan.com/spring-security/spring-webflux-rest-authentication

  10. Versioning • https://api.example.com/v1/authors/2/blogposts/13

  11. Documentation • Swagger

More Related