Introduction
In this article, I will cover the complete procedure of how to test web API Service using Postman. It is the simplest and most beautiful way to test and document your web service. Postman is a collaboration platform for API development. Postman's functions simplify every step of building an API and streamline collaboration so you can create better APIs—quicker.
How to Test API Web Service in Asp Net Core 5 Using Postman
In Postman for API Testing, the professional approach is to make the collection for API Requests for collecting the responses like getting PUT POST AND DELETE Request Response. Open the postman Click on Create Collection.
Name the Collection in Postman.
Now the collection is ready for collecting the API Request Response.
Add the API Request Responses Like PUT,POST, DELETE AND GET,
We are going to test the following use case for this article. In this article I am going to test the POST, GET, PUT, DELETE, AND UPDATE, Endpoints of Web Service.
Here in this example, we are going to test the Web Service using Postman Developed using the Asp.Net Core 5 Web API
Test POST Call in Postman
Here we are going to send the JSON object with the Following Properties
- {
- "id": 0,
- "userName": "string",
- "userPassword": "string",
- "userEmail": "string",
- "createdOn": "2021-04-16T20:38:41.062Z",
- "isDeleted": true
- }
Now Click on Raw and then Select the JSON.
If we want to Create the New Person in the Database, we must send the JSON Object to the End Point then the data is posted by Postman UI to POST End Point in the Controller then Create Person Object Creates the Complete Person Object in the Database.
Now you can see that our API gives us the server response == true so it indicates that a new record has been created in the database against our JSON Object that we have sent using Postman.
Test DELETE Call in Postman
For Deletion of Person, we have a separate End Point Delete Employee from the Database, we must send the JSON Object to the End Point then data is posted by Postman UI to call the End Point DELETE Person in the Controller then Person Object will be deleted from the Database.
In Deletion of the record just select body and the select, the form data pass the id value for the record you want to delete from the database.
We are going to delete the record against the given email if the API server response equal to true then our record deleted from the database successfully.
In the above two pictures, you can see that after hitting the Delete Endpoint our server response is true it indicates that our record has been deleted from the database against our desired Email.
Test GET Call in Postman
If we want to get the record of all the personal data from the database, we will hit the GET endpoint in our Web Service using Postman after the completion of the server request all the data will be given to us by our GETAllPerson Endpoint.
Hit the GET Endpoint for getting all records from the database.
After the successful execution of Web service, all the record is visible to us in the form of a JSON object in the database we have Only One Record so that
Test PUT Call in Postman
In put-call, we are going to update the record in the database. We have Separate End Points for All the operations like Update the Record of the Person by User Email from the Database by Hitting the UPDATE End Point that send the request to controller and in controller we have the separate End Point for Updating the record based on User Email from the database.
We are going to update the given below JSON Object in the database,
- {
- "id": 0,
- "userName": "Mudassar Ali Khan",
- "userPassword": "17859345@",
- "userEmail": "[email protected]",
- "createdOn": "2021-04-16T20:41:15.443Z",
- "isDeleted": false
- }
To given below JSON Object
- {
- "id": 0,
- "userName": "Sardar Mudassar Ali Khan",
- "userPassword": "17859345@",
- "userEmail": "[email protected]",
- "createdOn": "2021-04-16T20:41:15.443Z",
- "isDeleted": false
- }
We have sent the API JSON Response to the PUT Endpoint for Updating the Record in the database
After the successful submission of data, you can see that our server response is true it indicates that our data has been successfully submitted in the database
Conclusion
As a Software Engineer, my Conclusion about the Postman is that it the best Open API for Testing the RESTful API. As a Developer I have had a great experience with Postman for testing the restful API sending the Complete JSON Object and then getting the response in a professional way. It is easy to implement in Asp.net core Web API Projects and after the configuration Developers can enjoy the beauty of Postman Open API.