What is a REST API?

Api

First, you need to know what is a client-server architecture

So most if not all application we use these days follow this architecture the
the app itself is the client or the front-end part under the hood it needs to talk to a server or the back=end to get or save the data this communication
happens using the HTTP protocol the same protocol that powers our web so on the server we expose a bunch of services that are accessible via the \
HTTP protocol the client can then directly call the services by sending HTTP requests now this is where rest comes into the picture

REst is short for representational state transfer and I know it probably doesn’t make any sense to you because it was introduced by a PhD
student as part of his thesis but the theory aside rest is basically a convention for building these HTTP services so we use the simple HTTP protocol principles to provide support to create read update and delete data we refer to these operations altogether as crud operations now let’s explore this convention using every award example let’s say we have a company called devopsschool.com for renting out movies we have a client app where we manage the list of our customers on the server we should expose a service and an endpoint like this so calm slash API slash customers so the client can send HTTP requests to this endpoint to talk to our service now a few things about this endpoint you need to know

What is REST API ?

first of all the address can start with HTTP or HTTPS that depends on the application and its requirements if you want the data to be exchanged on a secure Channel you would use HTTPS after that we have the domain of the application next we have slash API this is not compulsory but you see a lot of companies follow this convention to expose their restful services they include the word API somewhere in the address it can be after the domain or it can be a subdomain like API that vid link aam there is no hard and fast rule after that we have slash customers which refers to the collection of customers in our application in the rest would be referred to this part as a resource.

We can expose our resources such as customers movies rentals on various endpoints so this is our endpoint to work with the customers all the operations around customers such as creating a customer or updating a customer would be done by sending an HTTP request to this endpoint the type of the HTTP request determines the kind of the operation so every HTTP request has what we call a verb or method that determines its type or intention here is the standard HTTP methods we have yet for getting data post or creating data put for updating data and delayed for deleting data now let’s explore each of these using our customers example

To get the list of all customers we should send an HTTP GET request to this address, not full name customers here it indicates a list of customers so when we send an HTTP GET request to this endpoint our service should send us something like this so we have an array of customer objects if you want a single customer we should include the idea of that customer
in the address then our server would respond with a customer object like this how to update a customer we should send an HTTP request to this endpoint and note that again we’re specifying the idea of the customer to be updated but also we should include the customer object in the body of the request so this is a complete representation of the customer object with updated properties

we send this to the server and the server updates the customer with the given ID according to these

Values similarly to delete a customer we should send an HTTP delete request to this endpoint but here we don’t need to include the customer object in the body of the request because all we need to delete a customer is an ID and finally, to create a customer we need to send an HTTP POST

request to this endpoint note that here because we are adding a new customer you’re not dealing with a specific customer so we don’t have the ID in the address you’re working the collection of customers so we are posting a new customer to this collector and that’s why we should include the customer object in the body of the request the server gets the object and create the customer flask so this is the restful convention we expose our resources such as customers using a simple meaningful address and support various operations around them such as creating or updating them using standard HTTP methods