API Basics

A basic overview of what APIs are and their components.

What are REST APIs

REST is an architectural style or design pattern for APIs. When a client request is made through a RESTful API, it transfers a representation of the state of the requested resource. Web services that follow the REST architectural style are called RESTful web services.

A RESTful web application exposes information about itself in the form of information about its resources. It also enables the client to take actions on those resources, such as creating new resources (for example, creating a new post) or changing existing resources (for example, editing a post).

What the server does when the client calls an API depends on the following information:

An identifier for the resource: This is the URL for the resource, also known as the endpoint.

Operation you want to perform on the resource (in the form of an HTTP method or verb): GET, POST, PUT, PATCH and DELETE.

HTTP Methods

HTTP defines a set of request methods, also known as HTTP verbs, to indicate the desired action for a given resource. Given below is the list of methods commonly adopted by [WEBSITE_NAME] APIs:

Verb Description Example
GET Requests a representation of the specified resource. Requests using GET should only retrieve data. Fetch all Bookings
POST Submits an entity to the specified resource, often causing a change in state or side effects on the server. Create a booking (not supported)

Parameters

Parameters are options you can pass with the endpoint to influence the response.

Parameter Description
Path Parameters Path parameters are part of the endpoint itself and are not optional.
Query Parameters Query parameters appear after a question mark (?) in the endpoint. Each parameter is listed in the query string right after the other, with an ampersand (&) separating them.
Request Parameters Request parameters are included in the request body and are used to send data via the REST API.
Response Parameters Response parameters represent the response to a request.

Success Response Status Codes

Given below is the list of the most commonly encountered success responses:

Status Code Description
200 The request succeeded, and resource fetched.
204 The request succeeded, but no resource fetched.

Error Response Status Codes

Given below is the list of the most commonly encountered error responses:

Status Code Description
400 The server cannot or will not process the request due to something that is perceived to be a client error.
401 Although the HTTP standard specifies "unauthorized", semantically, this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
404 The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid, but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well-known due to its frequent occurrence on the web.
422 Validation error
429 The server is processing too many requests at once and is unable to process your request. Retry the request after some time. Know more about Rate Limiting.
500 The server has encountered a situation it does not know how to handle.
502 This error response means that the server got an invalid response while working as a gateway to get a response needed to handle the request.
503 The server is not ready to handle the request. Common causes are a server that is down for maintenance or is overloaded.
504 This error response is given when the server acts as a gateway and cannot get a timely response.
Page Overview