Welcome to this video using parameters
and API calls. Up until now we've talked
about endpoints using GET calls, but in
this video we're going to dive a bit
deeper and look at how to use parameters
inside of API calls.
So Postman gives you a couple of ways of
doing this, but let's kind of dive in and
look at a real life example. So we'll
pull up the documentation here for the
SpaceX API. And you can see there's a
number of different endpoints that are
available to us here on the left. Well
the one we'll take a look at is the
launches API. So this is an endpoint that
gives us information about the different
launches that SpaceX has had, and is
planning in the future. So I've already
got this open for us in Postman here, you
can see I've got the URL in here, it's a
GET request and down here we can see
that it gives us back quite a big list
of information about the various
launches that SpaceX has done over the
years. So this gives us a big long list
of all the launches that have been done.
Now if we go back to the documentation,
we can see down here that it has a
number of optional query strings, and
then down here as well it has a number
of optional output control query strings.
So these are what we can call parameters,
query strings is a kind of parameter. So
you can see here's the parameter flight
ID, and then there's a sample of what it
might look like. And a number of
different parameters here. So let's take
some simple ones, let's look at limit and
we'll put that in. So we'll go over to
Postman, and Postman has this params tab
here in your setup that lets us quite
easily create this. So we'll just create
a key called limit, and if we go back to
the documentation it takes in an integer,
a sample of that is three. So let's put
an integer in, let's say two. So we put
that in and interestingly you can see
something going on here. So as we've
added this key in this value here the
URL appears changed. So instead of just
being slash launches, it now has this
question mark limit equals two. And so
that's how query string parameters are
encoded, they're encoded in the URL
itself. And Postman
takes care of this for us. So as we
create these parameters it automatically
adds them to the URL for us, and we can
see if we delete this here. So if we
remove this query that parameter is gone
from here as well. And so it nicely syncs
this up, so we can type it right back in
here if we want, so let's do limit equals
two. And it has added it back down here
for us as well. So Postman gives us this
flexibility to do it either way, and
helps us with setting this up. So let's
take a look at another parameter, let's
go back here, let's do this one, we'll do
order and we'll give it a value of
descending DSC. So let's put in our key
order, and our value des see. Now we can
see that Postman again has encoded this
into the URL for us, very handy it's
added the and here to concatenate these
two queries together for us, and set that
all up. So it's quite nice the way that
Postman handles this. So the examples
that we've looked at up until now our
examples of query parameters, or query
string parameters, but there are a few
other kinds of parameters that can be
used in an API as well. So if we go back
to the documentation again, and we scroll
down let's go look at this one here, get
one launched. And you can see here in the
URL it's got these squiggly brackets, and
flight number. So this flight number is
considered to be a parameter. So this
gives us the launch info for one
particular flight, given that flight
number. And so you can see here that's
the parameter, that's the sample. So this
is another kind of parameter, and this is
called a path parameter. Now there's also
a type of parameter, that's called the
header parameter we touched on those
already in the authorization. And in
Postman you can create headers here,
quite similar to the query parameters
but these don't get encoded in this, they
get sent as a separate header thing on
the request that gets sent to the server.
So the primary way that you would use
these typically is with authorization,
although in Postman you're probably
going to set up your
on the authorization tab. And then
there's another type of parameter that
is known as a request body parameter, we
don't usually use those with GET
requests but we will dig into them a bit
more when we get to POST and PUT
requests. So that gives you a quick
summary of how to use parameters in an
API. And in the next video, we're going to
get you set up for a testing challenge.
So we'll set you up for a find the
secret challenge, which is a challenge
where we will find a secret that's
hidden in the test API, hope to see you
there.