An Introduction To Backend Development and REST APIsAshwin GoelBlockedUnblockFollowFollowingJun 11Ashwin Goel Abhirupa MitraWhat do we mean by the backend of a website?An application generally has two parts- The frontend and the backend.
Many people fail to understand the concepts due to lack of clarity.
So, let’s take an analogy- suppose you are sitting in a car and the basic things that you can see and use are the brakes, clutch, accelerator, gear etc.
These are called the frontend components through which you can interact with the car.
But, when you use any of these, there is a series of actions happening behind the scenes which you are not aware of.
This is known as the backend.
The same way in any Web App you are able to interact with the frontend but the processing of your request is done at the backend.
Backend is basically the server-side architecture of the web.
Source: https://content-static.
upwork.
com/blog/uploads/sites/3/2016/09/26071621/Screen-Shot-2016-09-26-at-10.
15.
45-AM.
pngWhy does the web need a backend?The answer is same as what the backend does- it is used to hide the processing of any request from the user.
The backend includes processing, database and in total the whole machinery of any application.
If it gets available to the user the he can easily modify it and see the databases as well.
Therefore, the reason for having backend is to have a central processing point for everyone so that user doesn’t need to install any extra application apart from the browser.
Also having a backend means you are hiding the machinery of the application which means a user cannot see the databases and sensitive content unless there is a security vulnerability.
Components of a backend.
Server- It is the place where backend is stored and run.
These are high-powered computers that provides resources which the backend needs i.
e.
file storage space, processing power, security and encryption, databases and other web services.
Database- It is the brain of any Website that makes it dynamic.
If you are searching for anything on a website be it a profile on any social media or any product on E-commerce website it is the role of a database to take the query and fetch the required data to the user.
Middleware- It is any software (Server-side) that facilitates the connection between the frontend and the backend.
It acts as a medium that takes requests from the user and provides it to the backend and then facilitate the user with a response given by the backend.
Programming Languages and frameworks- There is a variety of languages available in which the backend can be coded however, the language is chosen based upon the usage because of the difference in their performance, memory usage, compatibility etc.
A majority of sites are built in PHP but nowadays NodeJS is gaining momentum and getting popular day by day.
One may also choose Python (Django, flask) for better processing power.
Other backend programming languages include- Java, .
NET, Perl, Ruby on Rails, etc.
An Introduction To REST APIs.
REST stands for Representational State Transfer.
It is a set of protocols/standards that describe how communication should take place between the computers and other applications across the network.
To have a clear understanding let’s take the car example again.
Suppose you want to drive a car so you know that you have to use accelerator, clutch etc.
to drive it.
The same way suppose a Web App wants to communicate to a Web Server.
So, a Rest API uses GET, POST, PUT, DELETE methods to communicate.
Therefore, we can conclude that REST is an architectural style for designing network applications.
It uses simple HTTP methods to communicate between clients and servers.
But it should be noted that HTTP and REST are not same.
REST API as known to us a state of rules that developers follow when they create their API.
One such rules says that we should be able to attain a specification when we link to a specific URL.
This URL is a locator which when browsed to generates a request and the specification it gets is called a response.
Source: https://modeling-languages.
com/rest-api-composer/A request for a particular data consists of 4 parts:a) The endpoint:The end point or the route is the URL we have requested for is structured as follows:root- endpoint/?This is usually the starting point of the API we are requesting from, and the corresponding path determines the resource you’re requesting for.
For eg:https://api.
github.
comhttps://api.
twitter.
comLet us assume we want to get a list of repos from a Github account of a user, through the Github API.
Github documentation asks us to use the following path:/ users / : username/ reposColons (:) on a path denotes a variable, these variables are replaced with their values.
Eg.
:username :username is replaced with the username of my Github account Developer Abhirupa.
So, in order to avail all my repos from github, the endpoint/ route will be:https://api.
github.
com/users/DeveloperAbhirupa/reposThe final part of an endpoint is the query parameter.
The query parameter allows us to modify our request with key-value pairs.
They start with a ‘?’ and each parameter pair is separated with an ‘&’.
b) The method:The method defines the type of request that is sent to the server.
There are 5 types of methods:GET: GET request is used to obtain a resource from a server.
On performing a GET request, the server looks for the data that has been requested and sends it back to usPOST: A POST request creates a fresh entry onto the database, and reverts back to us telling us whether the reaction of the entry has been successful or not.
PUT/PATCH: These requests are used to update resources on the server.
DELETE: This request deletes a resource from the server.
c) The headers:Header are used to provide information to both the client and the server and used for authentication, and also, may hold content about the body.
It is a component of a network packet, sent by either the browser or a client, requesting for a specific resource.
An HTTP request header allows us to access the website.
When we try to access a particular website, the HTTP request header is generated an correspondingly sent to the webiste, containing information mostly in the form of plain text, about the request made by the user.
In response to the request the web server sends back an HTTP.
There may be controversies about using the HTTP header, different sources saying that HTTP is a part of SOAP.
SOAP and REST cannot be compared directly.
SOAP is a protocol, or rather a set of rules whereas REST is an architecture.
So when security and authentication in HTTP are standardized, it can be called REST.
Keep watching out for our next blog post to know more about SOAP and REST APIs.
d) The body:The data or the body consists the message we want to send to the server.
Summarizing the Blog Post:This blog gave us a layman’s idea of what back-end development is all about and why is it necessary to put certain functionalities at the back-end of a website.
It also gave us a general idea about Representational State Transfer, or REST APIs, and a detailed idea about what we meant by requests and responses, in back-end development.
We have also given a brief idea about the 5 types of requests that can be made to the server.
In our next blog post, we would be elaborating on SOAP and REST APIs , simultaneously highlighting the differences between them.
We would also delve deeper into the development of a REST API.
Stay Tuned.
.