110 likes | 126 Views
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.
E N D
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.
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.
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
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
URI Formatting • Resources are Nouns, Not Verbs • HTTP methods are verbs • Singular vs Plural • /getAllUsers • /updateUser/{userId} • /updateUserArticle/{articleId}
Error Handling • Maintain uniformity • Should include message, status_code, type • An Example - https://www.devglan.com/spring-security/exception-handling-in-spring-security
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
Security • Some useful resource to secure REST endpoints. https://www.devglan.com/spring-security/spring-webflux-rest-authentication
Versioning • https://api.example.com/v1/authors/2/blogposts/13
Documentation • Swagger