REST API Design principles

September 20, 2021 | No comments

Introduction

In 2000, Roy Fielding proposed Representational State Transfer (REST) as an architectural approach to designing web services. REST is an architectural style for building distributed systems based on hypermedia. REST is independent of any underlying protocol and is not necessarily tied to HTTP.

What is REST

REST stands for representational state transfer. It is a set of constraints that set out how an API (application programming interface) should work.

REST API Design Principles

  • Uniform Interface: REST APIs are designed around resources, which are any kind of object, data, or service that can be accessed by the client. A resource has an identifier, which is a URI that uniquely identifies that resource.
    Use Noun and not verb to represent a resource
    In general, it helps to use plural nouns

  • Client-Server: Client and Server are independent of each others and the only way the client interacts is through the URI of the resources.
    Client and server can evolve independently.
    Client and server can be implemented in different tech stack.

  • Stateless : REST APIs use a stateless request model. HTTP requests should be independent and may occur in any order. The only place where information is stored is in the resources themselves, and each request should be an atomic operation.
    Being stateless means REST API can scale easily.

  • Cacheable: response to a request be implicitly or explicitly labeled as cacheable or non-cacheable.

  • Layered System: Client and Server should not be tightly coupled and if required and added any intermediate layer the API still should work.

No comments :

Post a Comment

Please leave your message queries or suggetions.