Rest API Terms — HTTP Request Methods & HTTP Status Codes

Aysel Aydin
4 min readJan 14, 2023

--

We have introduced the Python FastAPI in the before article. Before creating a basic REST API in Python with FastAPI, in this tutorial you will learn Rest API Terms — HTTP Request Methods & HTTP Status Codes.

Let’s start by defining commonly used terms.

  • API: API stands for Application Programming Interface. It defines how two pieces of software talk to each other.
  • Client: The client is the one who makes the HTTP request. For example, Browser is the client.
  • Server: The server is the one that receives the request and sends the response. Basically, the server is the piece of code that is responsible for accepting the request and sending the response back.
  • Request: HTTP request is made by a client, to a named host, which is located on a server. The aim of the request is to access a resource on the server.
  • Response: HTTP Response sent by a server to the client.
  • Endpoint: An API endpoint is the point of entry in a communication channel when two systems are interacting. An endpoint is a component of an API, while an API is a set of rules that allow two applications to share resources. Endpoints are the locations of the resources, and the API uses endpoint URLs to retrieve the requested resources.
    For example:
    With the Twitter API, we can retrieve data about tweets, direct messages, users and more.
    Let’s say you want to retrieve the content of a specific tweet. To do this, we can use the tweet lookup endpoint, which has the URL https://api.twitter.com/2/tweets/{id} (where {id} is the unique identifier of the tweet)
  • Swagger: Swagger is the standard way of documenting the Standard APIs.

There are mainly two types of web services.

  • SOAP Web Services: SOAP is XML based protocol for accessing web services.
  • RESTful Web Services: Restful Web Services is a stateless client-server architecture where web services are resources and can be identified by their URIs. REST Client applications can use HTTP GET/POST methods to invoke Restful web services. When compared to SOAP web services, these are lightweight and don’t follow any standard. We can use XML, JSON, text or any other type of data for request and response.

HTTP request methods

There are four different types of HTTP methods that basically tell the API what you’re trying to do with your data. (I will explain this part in more detail in the next post.)

  • GET Request
    Get Request will return the requested resource in a format that your program can read and use.
  • POST Request
    Post Request is mostly used for adding or updating information on the web service endpoints.
  • PUT Request
    Put Request will update the resource you specify.
  • DELETE Request
    Delete Request is used when wanting to remove data from the server.

HTTP Status Codes

HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped into five classes:

Informational responses (100–199)

  • 100 Continue
  • 102 Processing

Successful responses (200–299)

2xx HTTP status code represents that the HTTP request was successful.

  • 200 OK
    The request succeeded
  • 201 Created
  • 204 No Content

Redirections (300–399)

The 3xx HTTP status code indicates that the client needs to take some additional measures to complete the request.

  • 300 Multiple Choice
  • 301 Moved Permanently
  • 304 Not Modified

Client errors (400–499)

The server sends the 4xx HTTP response status codes to the client when some errors occur in the request made by the client. The client needs to send the correct request again to get the proper response.

  • 400 Bad Request
    The status code received when the server cannot process the request is a client error. (Example of client errors: URL string syntax error, invalid request message framing or deceptive request routing)
  • 401 Unauthorized
    This response means unauthenticated. So, the client must authenticate itself to get the requested response.
  • 403 Forbidden
    HTTP status code means access to the requested resource is forbidden. That is, the server understands the request but is refusing to authorize it.
  • 404 Not Found
    The server sends the 404 Not Found error when the requested resource is not available on the server. The reason behind this error could be that the site owner has removed the URL or the user has mistyped the URL.
  • 405 Method Not Allowed

Server errors (500–599)

The 5xx error messages represent the server-side error messages in which the website’s server is unsuccessful in performing a request.

  • 500 Internal Server Error
    The server sends the 500 Internal Server Error when has encountered a situation it does not know how to handle.
  • 502 Bad Gateway
    502 Bad Gateway error response means that the server while working as a gateway to get a response needed to handle the request, got an invalid response.
  • 503 Service Unavailable
    503 Service Unavailable Error is an HTTP response status code indicating that a server is temporarily unable to handle the request.
  • 504 Gateway Timeout
    This error response is given when the server is acting as a gateway and cannot get a response in time.

In the next Python article, we will create a basic Rest API in Python with FastAPI. Happy coding 🤞

Contact Accounts: Twitter, LinkedIn

--

--