How to Test ASP.NET Core Web API using Postman

How to Test ASP.NET Core Web API using Postman?

In this article, I am going to discuss How to Test ASP.NET Core Web API using Postman. Please read our previous article where we discussed How to Create, Build, Run and Test ASP.NET Core Web API Application. In fact, this is a continuation part to our previous article. A postman is a client tool used for testing Restful APIs.

How to Test ASP.NET Core Web API using Postman?

Now let us see, how to test ASP.NET Core Web API using Postman. First open Postman. Once you open the Postman, then click on the New button as shown in the below image to create a new request.

How to Test ASP.NET Core Web API using Postman?

Once you click on the New button, it will open the following Create New window. Here, simply click on the Request tab as shown in the below image.

How to Test ASP.NET Core Web API using Postman?

Once you click on the Request button, it will open the below Save Request window. Here, you need to do a couple of things. First, give a meaningful name to your API Request and provide a description of the API. Then you need to create one collection where you can create any of the Requests or you can use an existing collection to save this request. As we are doing for the first name, so, I am creating a new collection as shown in the below image.

How to Test ASP.NET Core Web API using Postman?

Once you click on the right arrow button, the collection will be created and the Save button is renamed with the collection name and also that button is now enabled. Simply click on that button as shown in the below image.

How to Test ASP.NET Core Web API using Postman?

Once you click on the Save to Collection button, it will launch the following window.

How to Test ASP.NET Core Web API using Postman?

Now let us understand the different components of the above Request.

Selecting HTTP Method:

You need to select the appropriate method of the API that you want to access. Here, in the dropdown, you can find the list of available HTTP Methods. As per your need to you select GET, POST, PUT, PATCH, DELETE, etc. In our example, the WeatherForecast API is of type GET, so, here we need to select the GET HTTP Method.

Selecting HTTP Method

Enter the Request URL:

In the Enter Request URL text, you need to provide the API URL that you want to access as shown in the below image. As we are going to access the WeatherForecast API, So, I enter the URL as https://localhost:5001/WeatherForecast.

Enter the Request URL

Params: If you want to send any parameters then you need to set those parameters as key-value pairs in the Params tab. In our example, we not going to pass any parameters to the Web API, so we keep this empty.

Authorization:

If your Web API needs some kind of authorization, then you need to provide such authorization here. In the type tab, you need to select the appropriate authorization and you also need to provide the value for the same. In our example, we don’t require any authorization, so we also keep this tab empty.

authorization

Headers:

The next one is the Headers tab. As you can see, the postman by default sends the following headers to the Web API. If your API needs some additional headers, then you can set those headers here only in the form of Key-Value Pairs. In our example, the API does not require any additional headers. So, we are only going with the default headers.

Headers

Body:

If your API accepts some data in the body, then you can send such data in the body tab. Further depending upon the type of data you can choose form-data, raw, binary, etc as shown in the below image. As our API is a GET request, as it doesn’t require any data, so none is selected by default.

Body

Now, click on the Send button, which will send the request to the Web API server as shown in the below image.

How to Test ASP.NET Core Web API using Postman

Once you click on the Send button, it will make a request to the Web API and the Web API sends the response back to the Client. And you can see the response in the response body as shown in the below image.

How to Test ASP.NET Core Web API using Postman

In the response, you can also check the HTTP status code, the time it takes, and the size of the data it received as shown in the below image.

How to Test ASP.NET Core Web API using Postman

This is how you can use Postman to test your Web APIs. In the next article, I am going to discuss how to create, build, run, and test the ASP.NET Core Web API project using Visual Studio 2019. Here, in this article, I try to explain How to use Postman to test ASP.NET Core Web APIs and I hope you enjoy this article.

Leave a Reply

Your email address will not be published.