What is RESTful Service?

Web is a place where there are tons of computers talking to each other. As the web grew, it became clear that we needed a common and secure way to allow others to interact with our application. This need gave rise to Representational State Transfer Architecture or more commonly known as REST architecture. REST defines a set of constraints for how the web should behave.

REST defines a?client-server communication model. The device making the request is called the?Client?and the device which is listening for the requests is called a?Server?The server is in charge of the resources. A resource can be anything like a HTML file, a JSON object, an image file or event a JavaScript file. The client-server communication happens with HTTP/HTTPS protocols. The actual logic for fetching the resource is abstracted behind the server and the client has no idea about what happens in the server. The resource might be fetched from the server the client requested or it can be fetched from some other server. The only thing client is concerned is that if they are getting the resource or not, and if they don't receive the resource, what is the reason for that? REST is also?Stateless, which means that the server has no idea about the previous calls from the client. The server does not hold on to information's for the client. A web service that obeys the REST constraints is called a?RESTful service.

No alt text provided for this image

The Client calls the server using http methods and gets a http response code and http response status along with the resource as the response. The most commonly used HTTP methods are

  • GET: This the the most widely used request method. When the client makes a GET request, it means that the client is asking for the resource mentioned in the URI. Multiple GET request for the same resource will result in same response from the server.
  • POST: The second most common request method. A POST request from the client comes with a request body that contains a structure of the resource itself. POST request is used to create the resource enclosed in the request body of a POST request. Every time we make a POST request, the server will create a new request even if the body of the request doesn't change.
  • PUT: A PUT request, just like the POST request contains a structure of the resource in its request body. A PUT request tries to find of the resource is already present and if its present then update the resource and if its not present it will create the resource. Hence PUT request will always give same response for same request.
  • DELETE: A DELETE request from the client means the client wants to delete resource.

The response codes from the server are in the following categories

Successful responses

When we get the expected response from the server. This includes the following status codes

  • 200 OK: This means that the request was success. This can be the result for any HTTP methods.
  • 201 Created: This means that the resource was created. This will be the response for either PUT or POST request.

Client error responses

When there is something wrong with the request made by the client we get one of the client error response.

  • 400 Bad Request: The server was not able to understand the request due to as the structure of the resource in request body is not same as the one server expects
  • 401 Unauthorized: The client is not recognized by the server and this is a resource only for recognized clients.
  • 403 Forbidden: The client does not have access to the resource. Unlike 401, here the server is aware of the client but the client does not have access to the resource.
  • 404 Not Found: The server cannot find the requested resource.

Server error responses

When there is something wrong with the server, then we get one of the server error response.

  • 500 Internal Server Error: The server encountered a situation it doesn't know how to handle.
  • 501 Not Implemented: The request method is not supported by the server.
  • 503 Service Unavailable: The server is not available to handle the request. This might be due to the server being down for maintenance.


要查看或添加评论,请登录

Mohan Brahmmadesam Manavalan的更多文章

  • Understanding JWT

    Understanding JWT

    What is JWT JWT stands for JSON web tokens. It is an industry-standard, for passing user claims between client and…

  • Understanding password storage

    Understanding password storage

    Storing passwords can be a challenging and painful task. With this post, I hope to highlight some of the challenges.

  • Serverless Computing

    Serverless Computing

    What is Serverless? The concept of cloud is to move the infrastructure our application is managed by the cloud vendor…

  • Deep dive into Git Rebase

    Deep dive into Git Rebase

    Whenever we have two branches and they are being worked on by separate members and we want to integrate the changes…

  • Demystifying Web Jargons Part - 2

    Demystifying Web Jargons Part - 2

    Welcome to the second part of my demystifying web jargons series. If you have not checked the first part, you can do so…

  • Understanding git a little better.

    Understanding git a little better.

    I see that a lot of people are confused and even scared of git, especially the beginners. To me, git is an awesome and…

    5 条评论
  • Demystifying Web Jargons Part - 1

    Demystifying Web Jargons Part - 1

    I have come to a realization that the world of the web is filled with so many jargons that are so commonly thrown…

    2 条评论
  • Want to learn about Closure?

    Want to learn about Closure?

    I have written an article explaining closures in javascript. Do check it out

社区洞察

其他会员也浏览了