Okay so hopefully you've been able to
find some 500 errors in the application.
There are these two ways to see that. But
in this video we'll walk through the
solution to the ones that I know of.
Now this service is not very robust, so
it's quite possible that you found
different errors than the one I found,
and if so great work. The whole point of
this exercise is to get you thinking
about how to test APIs, so any issues
that you find are helping you on that
path. Since I know how to do it, I'm gonna
follow a fairly direct path in this
video to showing the issues, but of
course you would have needed to do some
poking around to figure out the
structure and layout of the application.
So you probably didn't follow nearly as
linear a path as I did. So the first way
that we get to a 500 error is by trying
to post to an existing object. So I'll
bring up Postman here. We've got
something set up already so I'll walk
you through the process a little bit of
how we might do this. So let's change
this, let's do a GET on blog posts slash
one. I'll send that request and we get
back the first blog post as we would
expect. Now at this point let's see what
happens if we POST to this already
existing blog post, so let's change the
GET to a POST, and then we'll use this as
our body, and let's just let's change it
to raw JSON, and we'll just send back
what we have. Okay so let's try posting
this and see what happens. So we send
that, and if we scroll down here we see
we get a 404 not found. But let's try one
more thing, let's try posting this
without the explicit reference in the
URL. So we'll change this just to blog
posts, and you can see here we still have
this ID specified. So we're still saying
I want to create ID one, so let's send
this and see what happens.
We'd expect a similar response as before,
but here we got a 500 internal server
error because it in failed when it tried
to insert due to this duplicate ID. So
look at that, there's our first 500 error.
Now
in this case there's a little bit of
debate about exactly what the return
code should be when we try to post to an
existing resource, so let's leave this
one for now let's try to find another
500 error. So we really should not be
specifying the ID in the body here, we
should be letting the server take care
of it. So let's take that out, and let's
look at doing a PUT. And actually let's
switch this, let's look at it just a
whole different part of the application.
So let's change this to avatars instead
of blog posts. So we're gonna look at the
avatars, and let's actually just start
again with a GET so that we can see what
the structure looks like so you can
understand it a bit better. So we'll
change that to a GET, we'll send that and
this is what we get back as the data for
our avatar. And you can see the
information that it has, it's pointing to
various other items in the system that
the avatar is related to. So now let's
change this, and let's try to do a PIU. So
again we'll copy our body, let's change
this to PUT go here, and we will make
this the body of our request. Let's try
to do something interesting, let's see
what happens if we remove one of those
fields. Let's remove the blog post ID,
just delete that, and let's send this
request and see what happens. So we'll
send this request, and we scroll down and
it's okay here. And you can see that it
has automatically set this missing field,
so we didn't have a blog post ID up here
in the body that we sent, but it created
a blog post ID for us. Interestingly
though it has kind of set this to null.
So I wonder what happens if we try to
look at that blog post from here. So
let's go back up to our URL, let's change
it to a GET, let's try to get some
information, and if you remember we have
these parameters available, so let's add
the expand parameter. So we want to
expand out the resources, and let's
expand out that blog posts because we
had that as null here, this blog post
idea, so let's expand that out and see
what happens.
So we'll send that request and we get an
error saying it does not have a parents
blog post. So let's try to embed it
instead, and send that request and it was
okay. It's because we want to expand this,
so let's expand it and it blog post not
blog post is the parameter. And there we
get it, we get our 500 internal server
error. So we cannot read this property to
string of null is the actual error that
we get, but that shows you that there are
various ways of poking around at an API
that can expose issues. And so hopefully
you had some fun doing this on your own.
You can see here how I followed a fairly
linear path, but you probably used much
more trial and error, but hopefully it
was still fun for you and showed you a
taste of how you can go about
approaching testing an API. In the next
section, we're gonna start talking about
how to create automated regression tests,
hope to see you there.