Alright friends, so let's go and utilize one of the most popular tools for
working with
REST APIs and this is something known as Postman. So if I just set it for Post
man API and let's
click this top link here, if I go up to products and I choose Download Postman,
pretty much what
it's going to do is going to detect that I'm on a Macbook so it's going to give
me the option
to install for a Mac Apple chip or a Mac Intel chip but if you happen to be on
Linux or on Windows
you will see a similar type icon. Quite simply just click the one that resolves WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
you will see a similar type icon. Quite simply just click the one that resolves
to your platform
and in my case here I will choose the Apple chip okay. So the download begins
let's give this
a moment to complete. So once I have opened this Postman is prompting me to
create an account via
my web browser if I just click to open this manually. As we can see here I have
the option to create a
free account or sign up with Google and in this case here I will use my Google
account and all
it's going to do is going to ask you to enter in some questions so I'll just
say my name is John McGee
what is your role, let's just say other, let's just say Trainer and choose
Continue. All right so now I'm WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Continue. All right so now I'm
here in Postman what I want to do is I want to begin making some requests. So
this is what I will use
as my client to make the request. What I want to do now is to have a server to
talk to. If you search
for Go Rest API let's go down here click on this link for this one and
essentially this is just a
website used for testing Reist API's okay. So we see some resources such as
this endpoint here. This
is how we can get information on the users that are stored in this particular
server whereas if we
want to read Post we can use this particular endpoint same thing here for WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
want to read Post we can use this particular endpoint same thing here for
comments so this is exactly
what we talked about before particular URLs correlating to particular resources
on the servers. So right
now if I scroll on down what it actually says here is that if you want to make
particular requests
such as a put request or a post request or a delete request or a patch request
basically any
type of modifying behavior you need to have an access token which has to be
passed in your authorization
header. So just to make a simple get request we actually do not have to have WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
header. So just to make a simple get request we actually do not have to have
any type of authentication.
So let's go and see how we can do this then what I will do here is I will copy
this particular resource
here okay so grab you let's go to Postman and what I will do is I'll choose
this option to send an
API request. So inside here I can specify the method I want I can have a get a
post a put a patch
so on so forth. Now I just want to retrieve information I you read data so we
know the HTTP method
we use as a get request and now we just specify the resource we want to target
so let me just paste WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
so let me just paste
this in right here. Now we have our headers at the moment let's go and grab and
accept header okay
to specify what type of data we want so let's say accept and the type I'm going
to say is
application forward slash JSON okay now watch what happens if I just choose
send here give a moment
we send a request and look at this we're getting back a 200 okay response so we
recall straight away
this two tells us we have a success and a 200 like I say is just an okay
message as we see right here
nothing new was created but a request was successful. Now if I just go and WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
nothing new was created but a request was successful. Now if I just go and
scroll on down here in fact
let me just pull us up a little bit grab you look at this right here we have
all of this data relating
to all of the users on this particular server and because we requested in our
headers that we wanted
JSON data back look at what we're actually seeing here see all this all of this
is JSON
so let's say we wanted to get a different type of data say for example we want
to get the posts
let's grab you and all we do is modify the endpoint mortality right here and if
we just send off WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
we just send off
our request look at this right here completely different data we see the ID of
the post the user
ID pretty much who actually posted it the title as well as the body now the
actual data here
that's all fake data is just for testing so the content is not exactly so now
like you say if you
want to maybe create a new user via a post request as we see right here I'm
going to have to create my
own tokens let me get an access token here okay now all I will do is I will log
in via my google
account now right here I can see my access token I'm going to blood this out so WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
account now right here I can see my access token I'm going to blood this out so
you can actually read
it so what I will now do is in my headers here I'm going to add the new header
I'm going to add an
authorization header okay and for the value I'm going to say it's the word
better because it's
going to be a better token and then after that I'll paste in the token itself
now what I will do
is if I go back to the documentation if I want to create a new user right here
it says that I'm
going to have to use this particular endpoint public v2 users which is
basically the same one we
saw when we use the get request so let's grab this again paste in this
particular value WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
particular value
and I'm also going to add in a content type header okay and this time here I'll
say I'm going to have
application json I'll be sending over json data and inside the body here I will
choose raw and now
all I will do is add in the data that I'm going to add so let's have my color
brace for my json
object and I'll just say the name which is called as rest test let's have a
colon so the email is
rest test at example dot com I'll say the gender as female and the status is
going to be active WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
going to be active
and if I change this to a post request and then I choose to send this off we
can actually
see here we get a 201 a created response pretty much we've now created a new
resource within this
particular server and if I try to resend a request we can see here we're
actually now getting a
client error as denoted via the four status codes and the response is actually
telling us hey this
email has already been taken i.e the email that we use in this particular body
we can no longer use
it so what I could do is I could go and modify this one more time to say john WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
it so what I could do is I could go and modify this one more time to say john
blah blah blah
I've been some blah blah blah let's change this maybe to mail now we should not
have a clash if I
send this one off once again we've created a new entity within the server
itself so this is how we
can utilize postman to send requests to arrest APIs with that now done let's
devalade what we've
learned within this skill