Rest API

Rest API

REST API (Representational State Transfer API) is a software architectural style for APIs that uses HTTP requests to access data. REST APIs are a common way to connect applications and components in microservices architectures. 

Here are some characteristics of REST APIs:

  • Lightweight: REST APIs are faster and more lightweight than other protocols like SOAP (Simple Object Access Protocol). 
  • Scalable: REST APIs are highly scalable. 
  • Flexible: REST APIs are flexible and can be adapted to working syntax and platform. 
  • Cross-platform: REST APIs are portable across platforms. 
  • Programming language: REST APIs can be developed using almost any programming language. 
  • Data formats: REST APIs support a variety of data formats.

REST APIs are used in many applications, including:

Mobile apps: Lyft and Uber use REST APIs to access maps and schedule rides. 

Banking apps: These apps use REST APIs to access account data and support transactions. 

WordPress: The REST API provides a structured way to access content within a WordPress site. 

REST was originally created by computer scientist Roy Fielding as a guideline for managing communication on the internet.

In HTTP there are five methods that are commonly used in a REST-based Architecture i.e., POST, GET, PUT, PATCH, and DELETE. These correspond to create, read, update, and delete (or CRUD) operations respectively. There are other methods which are less frequently used like OPTIONS and HEAD.

  • GET: The HTTP GET method is used to read (or retrieve) a representation of a resource. In the safe path, GET returns a representation in XML or JSON and an HTTP response code of 200 (OK). In an error case, it most often returns a 404 (NOT FOUND) or 400 (BAD REQUEST).
  • POST: The POST verb is most often utilized to create new resources. In particular, it’s used to create subordinate resources. That is, subordinate to some other (e.g. parent) resource. On successful creation, return HTTP status 201, returning a Location header with a link to the newly-created resource with the 201 HTTP status.

The following are some of the principles of the REST architectural style:

Uniform interface

The uniform interface is fundamental to the design of any RESTful webservice. It indicates that the server transfers information in a standard format. The formatted resource is called a representation in REST. This format can be different from the internal representation of the resource on the server application. For example, the server can store data as text but send it in an HTML representation format.

Uniform interface imposes four architectural constraints:

  1. Requests should identify resources. They do so by using a uniform resource identifier.
  2. Clients have enough information in the resource representation to modify or delete the resource if they want to. The server meets this condition by sending metadata that describes the resource further.
  3. Clients receive information about how to process the representation further. The server achieves this by sending self-descriptive messages that contain metadata about how the client can best use them.
  4. Clients receive information about all other related resources they need to complete a task. The server achieves this by sending hyperlinks in the representation so that clients can dynamically discover more resources.

Statelessness

In REST architecture, statelessness refers to a communication method in which the server completes every client request independently of all previous requests. Clients can request resources in any order, and every request is stateless or isolated from other requests. This REST API design constraint implies that the server can completely understand and fulfill the request every time. 

Layered system

In a layered system architecture, the client can connect to other authorized intermediaries between the client and server, and it will still receive responses from the server. Servers can also pass on requests to other servers. You can design your RESTful web service to run on several servers with multiple layers such as security, application, and business logic, working together to fulfill client requests. These layers remain invisible to the client.

Cacheability

RESTful web services support caching, which is the process of storing some responses on the client or on an intermediary to improve server response time. For example, suppose that you visit a website that has common header and footer images on every page. Every time you visit a new website page, the server must resend the same images. To avoid this, the client caches or stores these images after the first response and then uses the images directly from the cache. RESTful web services control caching by using API responses that define themselves as cacheable or noncacheable.

Code on demand

In REST architectural style, servers can temporarily extend or customize client functionality by transferring software programming code to the client. For example, when you fill a registration form on any website, your browser immediately highlights any mistakes you make, such as incorrect phone numbers. It can do this because of the code sent by the server.

Benefits of RESTful APIs

RESTful APIs include the following benefits:

Scalability

Systems that implement REST APIs can scale efficiently because REST optimizes client-server interactions. Statelessness removes server load because the server does not have to retain past client request information. Well-managed caching partially or completely eliminates some client-server interactions. All these features support scalability without causing communication bottlenecks that reduce performance.

Flexibility

RESTful web services support total client-server separation. They simplify and decouple various server components so that each part can evolve independently. Platform or technology changes at the server application do not affect the client application. The ability to layer application functions increases flexibility even further. For example, developers can make changes to the database layer without rewriting the application logic.

Independence

REST APIs are independent of the technology used. You can write both client and server applications in various programming languages without affecting the API design. You can also change the underlying technology on either side without affecting the communication.

To view or add a comment, sign in

More articles by Rohit Singh

  • Azure Blob Storage

    Azure Blob Storage

    Azure Blob Storage helps you create data lakes for your analytics needs and provides storage to build powerful…

  • JCL

    JCL

    Job Control Language (JCL) is a scripting language that tells IBM mainframe operating systems how to run batch jobs or…

  • CRUD API

    CRUD API

    A CRUD API is an interface that allows users to perform create, read, update, and delete (CRUD) operations on a…

  • Amazon Aurora

    Amazon Aurora

    The Amazon Aurora is a relational database service offered from amazon cloud. This is one of the widely used services…

  • AWS Lambda

    AWS Lambda

    AWS Lambda is a cloud computing service from Amazon Web Services (AWS) that allows developers to run code without…

  • SQLite

    SQLite

    SQLite is a free, open-source, C-language library that implements a relational database management system (RDBMS)…

  • Qdrant

    Qdrant

    Qdrant is an open-source, fully managed vector database and vector similarity search engine that allows users to:…

  • PowerApps

    PowerApps

    Microsoft Power Apps is a platform that allows users to create custom business apps with little to no coding expertise.…

  • Microsoft Visio

    Microsoft Visio

    Microsoft Visio Visio is a Microsoft Windows based diagramming software that includes templates and symbols allowing…

  • NumPy

    NumPy

    NumPy is a Python library used for working with arrays. It also has functions for working in domain of linear algebra…

Insights from the community

Others also viewed

Explore topics