How To Use Postman To Test APIs
What Is Postman?
Postman is a browser extension that allows you to test their API functions locally on their own machine. As we've seen in the rest of the API series blog posts, APIs use the methods POST, GET, PUT, and DELETE using the HTTP protocol. When running an API server locally on our own computer, we can test GET operations using our web browser, but we can't do that for the rest of the methods. Postman allows us to do that.
What Is A Postman Collection?
Postman requests allow us to to make a request to any API method. For example, we may want to test a POST method for our API, and a postman request would have us specify an API request by entering the URL and request body to the API.
A Postman collection is literally a collection of postman requests. The purpose is to have a standard list of example requests that test all endpoints and situations our API could be in. This helps us ensure that our API is working correctly at all times, without needing to remember exact urls.
It's standard for any API project to create a Postman collection. It's akin to creating unit tests for code: it's just to make sure that the API is working correctly. The Postman collection can be both to our locally deployed API (for example, localhost:3000 while our terminal is acting as the server), and to an actual production API hosted on a cloud server.
How To Create A Postman Collection
Creating a Postman collection is actually very easy. First, download Postman if you haven't already. Search your browser's web store for Postman. Here's a link to for it on the Chrome web store. Install it, and launch the app. You should see the following screen:
Click on Collection. Enter a name and description, and press the Create button.
Next, we'll see a list of all of our collections on the left hand of the screen, and on the right side of the screen we see the tool used to make individual requests. Make a request by entering the HTTP Method, the URL, and any necessary headers, body, etc. Press the Send button to make the request.
To save this request to our Collection so that we can use it later, click the Save button. Enter a name for the Request, and a description. Select the Collect that we want to save this request too (srcmakeAPI), and then click the Save button.
You can see the request is saved to our collection, on the left hand of the screen. Click on the srcmakeAPI collection.
Press the run button. A new pop up will show up with all requests for this collection. You can run them all to ensure that your API's endpoints all work correctly.
And that's it. Make the requests as complete as possible with many examples so that you can adequately test your collection.
Postman is easy to use, and very necessary to make sure your API is working as expected. It's not hard at all to use, it just requires a little thinking to make sure your entire API is covered.
Also use it while developing to make sure the endpoint is working, as you code each one.
Like this content and want more? Feel free to look around and find another blog post that interests you. You can also contact me through one of the various social media channels.
Comments are closed.
Hi, I'm srcmake. I play video games and develop software.
Pro-tip: Click the "DIRECTORY" button in the menu to find a list of blog posts.
License: All code and instructions are provided under the MIT License.