Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Let's see how we can use a tool called Postman to interactively test our API.
Follow Along
To follow along committing your changes to this course, you'll need to fork the aspnet-fitness-frog-spa repo. Then you can clone, commit, and push your changes to your fork like this:
git clone <your-fork>
cd aspnet-fitness-frog-spa
git checkout tags/v2.4 -b using-postman
Postman
For more information about Postman, including installers and a complete list of features, see getpostman.com.
When developing an API, it's helpful
to have a way to test without having to
0:00
use a client application
that consumes your API.
0:04
Let's see how we can use a tool called
Postman to interactively test our API.
0:08
Postman is a native application available
for MAC OS, Windows, and Linux.
0:13
For instructions on how to download and
0:19
install Postman see their website,
getpostman.com.
0:22
I already have Postman
installed on my machine.
0:25
To make a get request,
you enter a URL and click the send button.
0:28
But first, let's start our
application in Visual Studio.
0:34
Set break points in both the get action
methods and start the application.
0:38
Once the application has started,
make note of the port number in the URL,
0:57
or simply select the URL, and
copy it to the clipboard.
1:03
Visual Studio randomly sets this
number for your project, so
1:07
your port number will most likely be
different than the one you see here.
1:10
In Postman, for
the request URL enter http://localhost
1:15
followed by the port number for
your application.
1:21
Or if you copied the URL to the clipboard
like I did, simply paste the URL
1:25
into this field and
remove the pound sign slash entries.
1:30
Then after the port number enter,
1:36
api/entries and click the send button.
1:40
Here we are in Visual Studio at our break
point in our first get action method.
1:48
Press F5 to continue execution and
switch back to Postman.
1:53
And here's the response data
formatted as JSON displayed
1:58
in the bottom section of the current tab.
2:01
Now let's try retrieving
a single entry resource.
2:06
To do that, just add a 1 after
the /API/entries path and
2:09
click the Send button.
2:14
And here we are in Visual Studio again.
2:19
This time we're at our break point
in the second get action method.
2:21
Press F5 to continue execution and
switch back to Postman.
2:26
We aren't returning any
data from our method, so
2:30
there isn't any data to
display here in Postman.
2:33
We'll finish implementing our
get methods in the next session.
2:36
Later in this section, we'll see how to
make requests that contain a message body,
2:40
for example,
a post request to create a resource.
2:45
Here on the left,
2:48
under the History section, we can see
a history of the requests that we've made.
2:49
Here's our first and second get requests.
2:54
We can click on the first get request and
2:57
click the send button to make
the request against the server again.
2:59
We'll continue to use Postman to test our
API throughout the rest of the course.
3:06
We're just scratching the surface of
what Postman is capable of doing.
3:11
See the teacher's notes for
more information about Postman.
3:15
Looking at the response data for
our first get request again,
3:18
how did the data that we returned from our
controller action method get converted, or
3:22
serialized, to JSON formatted data?
3:27
Coming up next, we'll take a look at
a feature called content negotiation and
3:31
learn how Web API serializes our data.
3:35
See you then.
3:39
You need to sign up for Treehouse in order to download course files.
Sign up