ASP.NET

Postman Web API Testing Tool – ASP.NET Web API

Contents

Postman is a REST Client designed for back end developers. Many software developers use this REST Client to share, test, document and monitor APIs. It is one of the most preferred options among developers with its advanced interface and many features.

In this tutorial, I will show how to test the Web API we created with the ASP.NET Core architecture via Postman without the need for a browser. Check out the ASP.NET Core Web API Entity Framework Scaffolding article if you missed it.

First, let’s make the necessary preparations before we start.

Download and Launch Postman

Postman has both paid and free versions, but we’ll go over the free version here. Also, you can run it through the browser but I recommend downloading and installing it. All you have to do is downlad and install it on your PC.

Launch Postman
Launch Postman

Here, open a new query window by clicking the plus button.

Postman Query Tab
Postman Query Tab

Run the Web API Project

Now, open Visual Studio and run the existing Web API project. The project must be running in order to send commands via Postman.

GET Request in Postman

The GET method is used to get data from servers. It is one of the most used methods.

To test the GET method, type the appropriate URL for your API in the bar that says “Enter Request URL” and press the Send button.

Testing GET Request in Postman
Testing GET Request in Postman

As a response, it would send the results from the database in JSON format with 200 OK Status.

POST Request in Postman

You can print data to the server with the POST method. Request parameters can be sent both in the URL and in the message body. It is safer to send parameters inside the body.

Since our data format is JSON here, we must specify application / json as Content-Type in Headers section before sending POST request. Otherwise, we’ll get a 415 Unsupported Media Type response.

Then, choose POST as your method and come to the Body section and write the information you want to send in Raw format. Then send your request with the Send button.

Testing POST Request
Testing POST Request in Postman

Status Code returned 201 Created and the data we sent was successfully added to the database.

PUT Request in Postman

You can update a resource on the service provider with the PUT method. Whichever resource you are going to update, it is mandatory to send the id of that resource.

For example, in the Tags table of my database there is a tag named “red” with an id of 1006. I want to change the name of this tag to “pink”. For this, I choose the PUT method as the request and write the appropriate id in the URL bar. Next, I write the data I want to change in the Body section and send it. So much!

Testing PUT Request
Testing PUT Request in Postman

The data we entered has changed in the database and returned 204 No Content responses.

DELETE Request in Postman

You can delete any data on the server with the DELETE method.

To delete the data, select DELETE as the request method and type the id of the data you want to delete in the URL and send.

Testing DELETE Request
Testing DELETE Request in Postman

The row of the id we entered was deleted from my database table and the status code was 200 OK.

Conclusion

As a result, Visual Studio runs our Web API project on the local ISP. And, we can’t test all HTTP methods in local. That’s why tools like Postman make our job easier.

Related Links

Serkan

Software Engineer. Problem solver. Music practitioner. Thinker. Industrious.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button