REST API’s :An Introduction

Aakash Verma
3 min readJun 30, 2020

--

According to Wiki :- Representational state transfer (REST) is a software architectural style that defines a set of constraints to be used for creating Web services .

More Generally an API exposes a set of data and functions to facilitate interactions between computer programs and allow them to exchange information .

Web services are purpose built web server that support needs of any particular site . Client programs use API (Aplication programming interface ) to communicate with web services.

REST is a architectural style that is commonly applied to design API for modern web services .This describes six constraints, thses constraints applied to the architecture were originally introduced by Roy Feilding in his Doctoral Dissertation (LINK) which defines the basis of RESTfull systems .

The six constraints describe above are :-

1.Uniform Interface : The uniform interface constraint defines the interface between clients and servers. It simplifies and decouples the architecture, which enables each part to evolve independently.

2.Client Server Architecture: The uniform interface separates clients from servers. This separation of concerns means that, for example, clients are not concerned with data storage, which remains internal to each server. Servers are not concerned with the user interface or user state, so that servers can be simpler and more scalable .

3.Statelessness : It Essentially means is that the necessary state to handle the request is contained within the request itself, whether as part of the URI, query-string parameters, body, or headers. The URI uniquely identifies the resource and the body contains the state (or state change) of that resource. Then after the server does it’s processing, the appropriate state, or the piece(s) of state that matter, are communicated back to the client via headers, status and response body.

4.Cacheable: As on the World Wide Web, clients can cache responses. Responses must therefore, implicitly or explicitly, define themselves as cacheable, or not, to prevent clients reusing stale or inappropriate data in response to further requests.

5.Layered System : A client cannot ordinarily tell whether it is connected directly to the end server, or to an intermediary along the way. Intermediary servers may improve system scalability by enabling load-balancing and by providing shared caches. Layers may also enforce security policies.

6.Code on Demand: Servers are able to temporarily extend or customize the functionality of a client by transferring logic to it that it can execute. Examples of this may include compiled components such as Java applets and client-side scripts such as JavaScript.

Rest API’s can be described by using following example, Consider yourself in a restaurant , You called the waiter and placed the order . The waiter then went to kitchen area of the restaurant and asked chef to prepare the items you ordered . Now In this case you act as a browser requesting for resource and waiter acted as an API who being a interface to the Restaurant Kitchen and you, help communicate without any problems or direct interaction which would ease the workflow .while kitchen act as a server providing the requested resource

HTTP Method’s for Restful services : —

POST : — It is used to create new resources , In other words, when creating a new resource, POST to the parent and the service takes care of associating the new resource with the parent, assigning an ID (new resource URI), etc.

Examples:

GET : — The HTTP GET method is used too retrieve a representation of a resource. GET returns a representation in XML or JSON and an HTTP response code of 200 (OK) in case of no error and in an error case, it most often returns a 404 (NOT FOUND) or 400 (BAD REQUEST).

Example:

  • GET http://www.ex1.com/12345
  • GET http://www.ex2.com/cute/1/
  • GET http://www.ex3.com/buckets/sample

PUT: — PUT is most often used for updating an already present resource by requesting the server with new details for the resource .

Example:-

  • PUT http://www.ex1.com/customers/12345
  • PUT http://www.ex2.com/customers/orders/98765

PATCH: — PATCH is used to modify data. The PATCH request only needs to contain the changes to the resource, not the complete resource.

Example:-

DELETE: — PATCH is used to delete the resource .

Example:-

That’s it this is the general introduction to understand What REST API’s are and how they work . Feel free to ask any doubts questions relevant to this topic in comments . Clap if you like it Thanks for Reading …

--

--

Aakash Verma

Computer Science Undergrad ,Tech Enthusiast , Loves writing about Technology