Articles

What is REST API? | REST API Tutorial | REST API Concepts and Examples | Edureka

December 3, 2019


Since the invention of the internet we
have been using different applications on web pages to get the data for various resources. However have you ever thought where does this data come from well it’s
the server’s from where we get the data so hello all this is Sahiti on behalf of Edureka and I welcome you to this session on “What is REST API”. So in the
session will mainly focus on how a client communicates with the servers to
extract the required information. So without wasting any for the time let’s
take a look at the topics for today’s session so we started a session by
understanding the need of REST API and then we look into what is REST API
after that I’ll talk about the features of REST API and then deep dive into the
principles of REST API finally I’ll tell you the methods of REST API and then end
the session by telling you how you can implement REST API or how you can create
a REST API so I hope the agenda is clear to you guys all right so before I move
on with the session I would like to request all of you who are interested to
learn the top trending technologies to subscribe to our a direct channel to get
daily notified on various concepts on the top trending technologies so let’s
get started with the first topic for today’s session that is why do we need
REST API now consider a scenario where you’re using to book my show app I am
sure that you know all of you must be using book minds your app on a regular
basis right now obviously when you use this app you must have observed that you
know the application needs a lot of input data as the data present in the
application is never static so what I mean by that is when you consider the
book – your app all the time the movies are getting updated on daily basis even
the show times and the places where the movies are shown or maybe not just with
respect to two movies but also with respect to the events the data keeps
getting updated on a regular basis so where do you think we get this data from
well this data is received from a server or most commonly known as a web server
so the client requests the server for a required information why an API
and then the server sends back a response to the plane over here the
response sent to the client is in the form of an HTML webpage now do you think
this is an apt response that you would expect when you send a request to the
server obviously no right just imagine yourself if you’re searching for a data
for a specific movie at a specific place and a specific time do you expect an
HTML page back as a response well I’m assuming the fact that you would also
say an oh right so since you would also prefer the data to be returned in form
of a structured format rather than a complete webpage the data returned by
the server in response to the request of the client is either in the form of a
JSON format or in the form of an XML format now both Jason and XML formats
are sent because you know they have a proper structure in which the data is
represented now if I talk about the JSON format and the XML format so as you can
see on my screen so for example let’s say you know we want to find out the
data of the movies which are coming soon at a specific city so what you can
simply do is if you just send a request of this particular information to the
client the server returns the data in either the JSON format or the XML format
so the JSON format it shows as as you can see in my screen so basically there
is a city and then there’s movies categories and in the category you have
coming soon when you come to the XML format in the XML format section you
basically have cities movies and then again we have a category section which
shows coming soon so over here if you observe the JSON format has basically
format of an object where you know the object values are returned to the user
and coming to the XML format the XML format follows a hierarchical data
structure in which the data can be returned now this sounds quite simple
right but the only issue which is present in this framework is that you
know you have to use a lot of methods to get the required information from the
server even if the data is returned in a simple format that is the JSON or the
XML format the only problem till now is that you have to do a lot of work to get
your data back like you know you have to put in a lot of to pause to get methods
and then you have to request for the data to be returned and so on for a
single information this sounds fine but imagine the scenario where you
continuously are thing for data and then you have to look
into so much of methods now this obviously becomes cumbersome now to
avoid such kind of scenarios what came into picture is the REST API so the REST
API creates an object and thereafter sends the values of the object in the
spawns to the client requests so now that you know the need of REST API is
next let’s look into what exactly REST API is so what is list API now as I just
mentioned breaths are just the fact that you can just create an object of the
data requested by the client and then send the values of the object in
response to the user now let’s say you know if you want to find out a scenario
of a specific movie let’s say you know if Infinity Ward is playing at Hyderabad
at the specific place let’s say you know an IMAX and then timing at 10 13 and 9
let’s say if we want to find out this particular data so to find out this
particular data what will happen is a client will send the request to the
server that yeah he wants to find out the data that you know the movie
Infinity Ward is playing in the city hives or bad at IMAX at 10:30 or not so
when the request is sent to the server what lets the API does is that you know
it creates an object of this particular request and then it finds out whether
you know it plays or not so it searches for the data in the server for the kinds
request if it finds outside you know if the data is present it just sends back a
response to the client with the values of that particular object so now if you
observe over here what’s happening you’re creating an object and then you
have some values of the object and what’s happening is that the values of
the object are sent to the client so that’s basically the state of an object
is sent to the client so each and every time you don’t have to generate a new
object so what happens is new is just passing the state of an object to the
client so since you’re just passing the state of an object that’s where the term
representational state plants were comes in now if I have to define rest for you
then the presentation state transfer or rest is an architectural style as well
as an approach for communication purposes that is often used in various
web services development this architectural style of rest helps in
leveraging the lesser use of bandwidth to make an application more suitable for
Internet and is often regarded as the language of
Internet and is completely based on resources
apart from this it’s also a stateless client-server model that you can
understand about so rest is really simple guys it’s just an architectural
style as well as an approach for communications purposes that is often
used by various web services development so now that you know what rest is let’s
look into the features of the REST API so the features of REST API are as you
can see on my screen it’s more simpler than so it has a proper documentation
and it gives you proper logging of error messages so before the rest came into
picture what we had was so so after the REST API took over the world then you
can just say that you know you can use the REST API in a much easier way than
so coming to documentation so it comes with a good documentation so that you
understand each and every step of how you can create a REST API using various
technologies waitis frameworks and how you can embed them for your applications
and finally coming to error messages when I say error messages it has proper
logging information of the errors so for example let’s say you know you’re
creating a REST API using a specific framework and then you’re stuck
somewhere what happens is you get a proper message about the error that’s
coming up so that the user can understand what’s the error about and
candy bar get these were the features of REST API now let’s move forward and
understand the principles of REST API well there are six clowned principles
laid by dr. fielding who was to want to define the REST API design in 2000 so
the six count principles are stateless client-server uniform interface cashable
layered systems and code on demand so talking about stateless what I mean by
stateless is that when the requests are sent from a client to the server it
contains all the information that is required to make the so understand it so
it can be a part of a URL or query string parameters body or even headers
now the URL is basically used for uniquely I didn’t find that the source
and the body holds the state of the requesting resource once the processing
is done by the server an appropriate response is sent back to decline through
header status or response what coming to client/server when I said
client-server what I mean by that to start you know it has a uniform
interface that separates the clients from the server’s so separating the
concerns basically helps in improving the users interface portability across
multiple platforms as well as enhance the scalability of the server components
coming to uniform interface to obtain the uniformity to the application rest
has defined for interface constraints which are resource identification the
source manipulation using representations self descriptive
messages and hypermedia as the engine of the application state coming to
cacheable in order to provide a better performance the applications are often
made as cacheable it is done by labeling the response from the server as cashable
or non cashable either implicitly or explicitly if the response is defined as
cashable then the client cache you can reuse to the spawns data for equivalent
responses in the future it also helps in preventing the reuse of steal data next
moving forward with layered systems the layer system architecture allows an
application to be more stable by limiting the component behavior this
architecture enables load balancing and provides shared caches for promoting
scalability the layered architecture also helps in enhancing the applications
security as components in each layer cannot interact beyond the next
immediate layer they are and finally coming to code on demand the core on
demand is an optional constant and is used the least it permits a client score
or app list to be downloaded and extended wire the interface to be used
within the application in essence is simplifies the clients by creating a
smart application which doesn’t rely on its own code structure so now that you
know the principles behind the REST API next let’s take a look at the methods of
the best api now all of you might be working with the technologies of web
right so what do you do you work on crude applications so when I say crude I
mean that you know we create a resource we read the source we update a resource
and we delete a resource now for example if you consider the URL that you can see
on my screen what it says is that you know HTTP and then book my shore comm
slash now Adar slash movies if you observe over here for quite a
long time I’ve been saying the word resource do you know what that means
well resource is basically what you want to do so for example let’s say you know
we want to search for the city in Noida and then movies so if you consider the
URL that you can see on my screen if you hadn’t put it like this then you would
have searched it like you know search is equal to noida and then you put one more
query parameter of movies so basically you would have to put to query
parameters that is Noida and movies and before that you had to put the URL but
obviously that doesn’t sound like a resource right because you always cannot
just put question mark and then you cannot keep putting the query parameter
instead of that you can just use these URLs like you know with slash you
mentioned the first parameter and with the second slash you mentioned the
second parameter and so on so that’s basically how your data structure might
also be defined in the server so that’s what basically I mean by a resource so
when I say the source the source is something that a client wants to know or
maybe the data that client is looking for word so now to do these actions that
is basically to create a resource read in the source update and delete the
resource you can actually use the HTTP methods which are nothing but the
methods of REST API so for creating a request you can use the post method for
reading a request you can use a get method for updating a resource you can
use the put method and for deleting a resource you can use the delete method
so all these methods together are basically the HTTP methods that is the
post get put and delete are the HTTP methods so now that you know what is
Leste api and what all you need to mind in order to deliver an efficient
application let’s next look into how you can create a REST API so for this
practical demonstration what I’m going to do is I’m going to create a simple
crude List application using Noches so to build the application basically I’ll
be using no jails expressjs Joey and note born apart from that let me tell
you that you know I’ll be using the webstorm ID to write and execute the
codes so you can use any ID according to your convenience so let’s start by you
know creating our REST API using node.js so what I’m going to do is I’m gonna
basically create a project directory which you know I’m gonna have all the
project related files so let’s say you know I just right click over here and
then let me just create a project directory let’s say demo for West API
now basically this project directory is initially blank as you can see on my
screen but after a while once I install all the required libraries and packages
you’ll see that you know package dot JSON file and package lock that JSON
file automatically created I’ll open my command prompt and then what I’ll do is
I’ll dam get to my demo folder so if you observe over here my demo folder was an
e directory and the for the name is demo forest API so what I’ll do is I’ll just
type in E and colon over here and then unmentioned CD and type in demo for rest
API right so automatically I’ll never get to my project folder through the
command prompt now what you have to do is you have to first initially install
node.js so to install node.js it’s really simple you have to go to their
official website and then you have to choose the LTS version based on whatever
is your pet like Windows 32 bit or 64 or maybe other curdles according to that
you download your version double click it and automatically node will be
installed so since I’ve already installed node in my system I’ll just
open the version and show you so as I type in node – – version you can clearly
see that I have the version 10 point 16 point oh so that means our node is
installed now what we have to do is you have to basically call the NPM package
to initialize the NPM modules into your system so to do that what you will do is
you will type in NPM in it so this will basically initialize all the NPM modules
into your system once you do this what you see is basically you’ll be asked to
enter the details for your project for example let’s say package name to be
demo right oh it says you cannot put in capital letters right so I’ll just type
in demo over here and then version let it be 1.0 point only so I’ll just click
on enter description let’s say we mentioned
it’s hands-on for creation of REST API after that entry point this is the main
thing that you basically have to enter so remember the fact that you have to
mention the entry point file so over here I’m going to mention it to be
script or change so this is basically from where our process workflow is going
to start and then after that we just click on enter after that you’ll see you
have test command I’ll just click on enter get repository enter keywords
enter author let’s say I put in my name and the lysis to be the same so after
that it will ask you for a confirmation so basically the project name to be demo
version 1.0 0.0 description to be hand-sewn for creation of REST API main
to be script or cheers and then so on so if it’s okay I’ll just click on Y and
enter so whatever you define till now is basically the metadata for your project
so if I shift back now you will automatically see that you know the
package file has been created so now if I go back to my command prompt what you
have to do is you have to next install expressed or J’s to install expressed or
J’s what you have to do is you have to mention npm i and then mention the
library name that is express so you automatically see that you know it is
getting downloaded so let’s just wait for it to be installed
so the Express is basically a web framework which can be used along with
node.js so this is a web framework which allows you to create restful api with
the help of helper methods middle layers to configure your application after that
similarly you’ll have to install Joey to install Joey I’ll type in NPM I J oh I
write so once I mentioned that you’ll see that you know Joey library is also
getting installed Joey is basically used to validate your information whether
it’s in the right format or not so all the time you don’t have to validate your
server you can just directly install this library and this library will
validate the information for you after that you also have to install node one
so to do that what I’ll do is I’ll just type in NPM I – G
I’d mention note 1 and click on enter so as you can see note 1 is also getting
installed so let’s just wait for that to happen again so as you can see Nordman has also got
installed now note one is basically used to keep a watch on all the files with
any type of extensions present in the folder that is basically the project
folder also with note 1 on the watch you don’t have to restart the node.js server
each time any changes are made so basically what happens generally is that
if you don’t use note 1 then you have to restart that server anytime you make a
change so with the help of node 1 you don’t have to do that automatically node
1 will implicitly detect the changes and then restart the server for you now once
you’re done installing all these frameworks let me just open the package
to adjacent file and show you so if I just open the package dot JSON file with
webstorm alright so let me just zoom in a little bit so as you can see when I
open my package to JSON file what you clearly see that is whatever metadata
that you had entered when you were initializing your npm module right so
that’s basically demo and the description and then was the main file
and so on so this was about the package to JSON file guys now what you have to
do is basically you’ll have to define the entry point for your application
right that’s basically a workflow now to do that you have to basically define the
script or chase file that you had mentioned in your package store JSON
file so to do that what you’ll do is you go to your demo folder over here right
click over here and then let’s say we create a new JavaScript file well name
it script or chase and then we’ll click on OK now in the script or JS file let
me just put in the code that I’ve already coded and then I explain you
step-by-step what’s happening right so now let me just zoom in a
little bit all right so as you can see this is
basically my script or chase file so don’t worry I’m going to explain you
each and every step and then you’ll understand clearly how we are sending
information to the client and how the server is sending us back the response
initially as I told you before that you know we had installed expressed so what
we’re going to do is first we go to import Express so to do that what you’ll
do is you’ll mention Const and Express and then equal to a require Express
you’re basically assigning it to available Express over here and then
you’re just importing that particular library over here
similarly goes for Joey so both these libraries are imported to your file now
what you have to do is you have to create an Express application right so
to do that what you’ll do is you’ll basically use this particular variable
that you are created over here that is basically expressed and then
assign it to the app variable so further what we are going to do is we’re going
to use this app variable to understand the application and away’s actions on
this application right so we’re going to use this so now when I say we are going
to use this particular variable so basically you have to make sure that you
know that particular variable is using it right so for that you’ll just put app
dot use and then you’ll mention Express or Jason because we want to use a JSON
file what I mean by JSON file now for any application to work you have to put
in a data base right you can either use my sequel MongoDB or any other kind of
databases so over here I’m now going to connect it to any such databases I’m
going to just use a JSON file which has a list of the data that way we are gonna
enter and that will be stored on a server so the data is basically stored
in the JSON format so that is the reason we’ll be using Express not Jason now
talking about server so when a client sends a request to the server initially
the server has to be running so for that it needs a specific port so what I did
was I assigned the port environment variable automatically to 8080 right so
basically what’s happening is that you don’t have to assign it again and again
when you use an environment variable automatically what I did was that you
know the server will be running on the port 8080 and then to just give an
output that you know yes the server is running or not I’ve just printed a log
message saying they’re listening or the port and then port number will be
mentioned that will be basically eight over here so to make sure that you know
the server is running and then you know the server is connected to our system
that is basically our application from where we want the data to come so we
will just use this command sing AB dot listen and will basically make the
server list to the port that is 8080 over here and then we will display the
message so that’s with the server now if you observe I’ve told you one thing over
here that is a client will send the request to the server right and the
server already has a set of data so to basically define that data I have
created an object of customers so over here that is basically the object of
customers which have a specific name that is basically title and an ID so
this particular data will be initially stored into a server and then we can
play around with the data based on whatever request that we send so what
will return the data that is with giving data to the server after that let’s
start by you know understanding basically the HTTP methods that I just
discussed with you that is get put post and delete so what I’m going to do in
this hands-on is that I’m going to basically get all the data from the
server then I’m going to basically find an information of a specific customer
also I can delete information about a customer and finally I can also update
information about a customer so let’s understand the same so initially let’s
start with the get method so if you remember from our presentation that the
get method was basically to read the resource so what I’m going to do is I’m
going to mention any URL and then what I’m going to do is if I just type in a
URL then automatically I’d message should be displayed right so over here
I’ve mentioned the URL to be sliced or whatever it is localhost colon 8080
slash orthotic Lee this will basically send the message that you know welcome
to ad breakers REST API now over here if you sing what is the parameter so
basically a request and response are the parameters that are used in the get
method apart from that when I say AB dot ket what I mean is that you know
basically we want a handler to handle all the requests on a specific URL now
this URL that I’ve mentioned is according to my convenience it has
completely users perspective what URL they want to mention so you can mention
slash even then the code would work and even then you would display the output
so over here request is basically what is
and from the client side and the sponsor is basically what is sent from the
server side so the request over here will be the URL so whenever I type in
localhost colon 8080 slash are accursed from the client side will be sent to the
server and whenever the server identifies this particular URL this
particular message would be displayed coming to the next message that is AB
dot ket and then we are mentioning in the URL API customers so now what I’m
gonna do is I want basically the list of customers so that is basically whatever
list I have mentioned in this particular object so for that what I’ll do is I’ll
again similarly mention the URL that is basically localhost colon 8080 /ki slash
customers so whenever a client types in this particular URL what I want in
response is basically the list of customers that we had mentioned and we
had stored on a server side right so that is basically all the five details
so to do that what I will do is unmentioned the command rest send and
mention customers over here so that is basically returning our customer object
now let’s say you know we want to get the information of a specific customer
let’s say you know we want to get the information of ideal of Josh right so
basically his IDs – right so what I’ve done is in the URL I’ve mentioned that
you know it will be slash API slash customers slash ID so whenever you send
the request from the client side what you have to mention in the you are in
this basically localhost colon 8080 /ki slash customers
/ – so whenever you send this request a response will be sent from the server
side showing you the details about the second ID that is basically titled Josh
and ID – B – so don’t worry I’m going to show you all that outputs when I run
these codes so before that let’s just understand these codes step by step so
now if you’re wondering how is this happening right how is the REST API
understanding the fact that you know we have to search for the ID – in the
server side so basically that’s happening through this particular line
over here so basically we assign the customer object to customer dot fine and
then what we are doing is whatever query parameter that we are passing in the URL
is basically checked with the customer ID so for example it’s a customer ID –
is present only if it is successful it will return the data else let’s say you
know there’s no specific customer ID for example let’s say
you have only five IDs over here right now let’s say you know if someone just
types in slash six so basically is searching for the sixth ID and you know
that you know there’s no sixth ID present then what happens is that a four
zero four error will be displayed saying that oops can’t find what you’re looking
for right so basically this is also users perspective of how you want to
display the data so we are I used four zero for error so that is basically the
status I’m checking the customer is not found and then you display this
particular message so that’s what is happening when the customer ID is not
present now I hope that you know you’ve understood the get method now let me
just run this code and show you the outputs so to show you the output and
test the application what I’ve done is I’ve used postman so postman is
basically a chrome plugin which is used to send the request to the servers so
I’ve already installed that otherwise it’s really simple to install guys so
what you can basically do is you can just click on the plus button over here
and then you can mention the URL so as I was telling you you have to mention the
localhost colon 8080 and let’s say we mentioned slash and then over here you
basically have to choose the method so we’re I’m choosing the get method now
before I hit on send what you have to do is you have to start your server right
so for that what I’ll do is I’ll go back to my command prompt and then I’ll
mention node script dot chase so once I mentioned that you’ll clearly see an
output that you know listening on port 8080 that means our server is up and
running now if I go back over here and then if I just click on send you’ll see
that you know we get them display message saying welcome to Eddie rakers
REST API so that’s what you basically saw over here right so whenever we
mention a slash you’ll see the output as welcome to Eddie rakers REST API now
let’s say you know we mentioned slash API slash customers then according to
our code we have to get the list of customers so I’ll switch back and then
I’ll mention API slash customers and let the method to be get again and click on
send so once I click on send you can clearly see an output that you know we
have kept all the five details that we had mentioned in our script of J’s file
right so that’s basically the list of customers apart from that we also saw
one more thing you know if you want to get information
about a specific customer so let’s say you know you want to get information
about the third customer so that’s basically ID three so I’ll just put on
slash over here and mention three and click on send over here so when I click
on send you’ll clearly see an output that title Tyler and ID three so that’s
how basically the get method works and that’s how basic your API is helping you
to connect the client request to the server and so that the server can send
back the response to the client now let’s move forward with the next method
that is the post method so if you remember from your HTTP method you’ll
see that here the post method was used to create right so whenever you want to
create a resource you use the post method so now let’s just create a new
data right so let’s say you know we want to create a new data and then we want to
push it to our server so for that what you’ll do is you’ll use app got post so
app is the same variable that you are created over here that is basically for
our application variable so app dot post and then what you’ll do is you’ll
mention slash API slash customers and then what you’ll do is you’ll just
mention the title if the title is fine and if it is validated so basically when
I say validate customer what I mean by that is we have created a function to
validate information about the customer so only if the information is present in
the correct format the customer information will be validated and yes
the customer information will be pushed in to the server or if it’s not then
automatically there’ll be an error thrown so over here basically our
function validates Tila customer information and our condition is
basically that you know the title should be minimum of three characters right if
it is less than that then obviously it will see that you know it is not a valid
information and then it will show an error so that’s what is basically
happening so if I go back to my post method over here
you’ll see that you know if we’ll use this function of validate customer and
then if it is validated what will happen is automatically the customer ID will
increase by one and title will be stored by the title that you mentioned so
basically that’s what is going to happen over here so remember the fact that
since our customer ID is incremented automatically you don’t have to mention
the customer ID in your request you just have to mention the title and
then if the title is greater than three that is basically it has a minimum
character values of three then it move forward and then automatically the
data will be pushed into the server so when I say push automatically it has to
increase the stack right so initially our server had five values in its stack
now we won’t the sixth one also to enter so for that what we’ll do is we’ll use
this function of customer dot push customer right so basically we will push
the new value of customer object into the customer and then we’ll increase the
stack once it is done we’ll just send a response again back to the client saying
that here that particular ID has been created into the stack so let me just do
the same over here I’ll just shift back to my postman and now let’s see you know
I put post over here and then I go back to API customers and then what I do is I
go to body over here and then choose raw and let’s say I copy this part base it
over here and let’s say we mentioned the name to be mark right so mark is
basically having four character values so that means this customer information
should be validated so over here I’ll mention title mark and then in the text
option I’ll just go and add Jason right so basically this will be identified as
a JSON object and then what I’ll do is I’ll click on send so once I click on
send you’ll see an output that you know automatically ID generated is six so
that means we had five and then automatically it got incremented by one
now if I go back to the get method over here and then I click on send you see
the information of all the six values that we have stored in our server so
basically a stack has increased so that’s how guys you can use the post
method also now moving forward with the port method the port method is basically
used to update an existing resource so if the resource is not found it’s again
going to throw an error but yes if the resource is found it can definitely
update so let’s see the same how that’s happening so to update a resource let’s
say you know we consider an example of updating a specific customer IDs name
right so let’s say you know we had all the six IDs right so for example let’s
say we update some customer 3 is ID and then we mentioned the name to be Tyler
Patterson right so for that what I’ve coded is basically that whenever app dot
put that is basically app is again the same object that you had created over
here that is the Express application whenever it is with a put method and has
a specific URL that is a customers and then you mentioned the ID
which were IDs you want to update whenever the client sends this
particular request what happens is that initially it is first found whether the
customer exists or not for example let’s see no we mentioned
the ID to be 7 so we know that unit it’s not present in the stack right so what
happens is it will throw an error so over here I’ve put in the 4 0 4 error
and then I’ve mentioned the text to be not found right so it basically says the
customer is not found so there’s no resource with the ID 7 so obviously you
just can’t update any the source like that but yes if the customer is found so
for example it’s a we’re taking third one so the customer will be found then
what will happen is you’ll just validate the customer so in your input let’s say
we’ll put I’ll a partisan then whenever you mention this title automatically the
title will be updated for the third ID now after everything is done the server
has to send a response back also right so for that this particular command is
used that is response end customer so basically the customer object is updated
with the new values and then the response is sent back to the client
so let’s look into the same so what I will do is I’ll take the third one and
then I’ll mention the title to beat Tyler partisan and then I’ll choose the
message to be put over here and then I’ll click on send once I click on send
if I scroll down you’ll see the output that you know the title is Tyler
Patterson for ID three right so now if you just want to look into the stack
what I’ll do is I’ll go to get remove this ID over here
click on send over here again and then you’ll see the updated list that you
know the ID three has been updated and the new value is Tyler Patterson so
that’s how basically you can use the put method to update your resources
now finally coming to the final resource guys that is that the lead resource so
the delete method is basically to delete any specific resource so it it’s as
simple as the name suggests so to do that what I’ve done is I’ve chosen this
Abdur delete and then have chosen that URL to be API customers ID so what I’m
going to do is I’m gonna smell in a specific ID let’s say the second ID I
want the data to be deleted for the second ID so that’s what I’m gonna send
at the request ass and then what will happen is first initially again a
condition will be checked whether you know the customer exists or not for
example I’d say the ID – doesn’t exist then automatically again an arrow will
be sent back the saying that you know not found but yes if the customer exists
and what happens is you basically have to remove that particular data right so
you basically splice from that particular data all the data that is
present in id2 is removed and automatically the stack is pushed
forward right initially you had six values now you only have five values
right but yes remember the fact that you know the ID doesn’t get updated
automatically over here the ID remains the same well I leave it forward to you
guys to explore how you can update the ID automatically whenever your resources
removed from the server so apart from that finally after the data is getting
deleted we want the server to send a response back to the client right so for
that we again use rest or send customer that is basically our object now I’ll
shift back to my postman and then I’ll just choose this option of delete and
let’s say you know I mentioned the ID to b2 and then I’ll click on send so once I
click on send you’ll see an output that you know title George and ID two will be
deleted so when I go back to get method and put customers over here and remove
the ID you’ll see we get the data of one three four five six but the second one
is missing that’s because you know the data has got deleted so that’s how
basically guys you can use various HTTP methods that is basically the REST API
methods to communicate with client and server and to understand how a request
from the client is processed by the server and how the server sends back to
the sports so guys with this we come to an end of the session I hope all of you
found it informative so if you have any further queries related to the session
please comment in the comment section below until then that’s all from our
site today thank you and happy learning I hope you have enjoyed listening to
this video, please be kind enough to like it and you can comment any of your
doubts and queries and we will reply them at the earliest. Do look out for
more videos in our playlist and subscribe to Edureka channel to learn
more happy learning.

You Might Also Like

No Comments

Leave a Reply