

POSTMAN WEB API HOW TO
So I’d love writing this guide to help you understand how to use Postman for testing REST APIs in your daily work.In details, you will learn how to test CRUD APIs (Create, Retrieve, Update and Delete) using Postman API client which is the foundation tool of Postman platform. Here, in this article, I try to explain how to Implement the POST Method in ASP.NET Web API Application step by step with a simple example.Postman is a popular platform for designing, developing and testing APIs, and developers love using Postman for testing REST APIs because of its intuitive, easy-to-use user interface and comprehensive features. In the next article, I am going to discuss How to Implement PUT Method in Web API Application with an example.

POSTMAN WEB API CODE
When an item is not found, instead of returning NULL and status code 200 OK, return 404 Not Found status code along with a meaningful message such as “ Employee with Id = 15 not found“.With the 201 status code, we should also include the location i.e.When a new item is created, we should be returning status code 201 Item Created.If a method return type is void in Web API Service then by default Web API Service returns the status code 204 No Content.Points to Remember while working with Web API Post Method: the URI of the newly created item as shown in the below image. Notice in the response header we have status code 201 Created and also the location i.e. Return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex) Īt this point, issue another Post request from Fiddler. Var message = Request.CreateResponse(HttpStatusCode.Created, employee) Public HttpResponseMessage Post( Employee employee)

public class EmployeesController : ApiController

To achieve this, we need to modify the POST method as shown below. With the 201 status code, we may also include the location i.e. As per REST standard, when a new item is created, it should return the status code 201 Item Created. The problem here is that since the return type of the Post method is void, we get status code 204 No Content. This works fine and adds the employee to the database as expected. When we click on the Execute button, it will give us the below Response. Finally, click on the Execute button as shown in the below image.In the Request Body, include the employee object that we want to add to the Employees database table in JSON format.This tells that we are sending JSON formatted data to the server Run the application and Fire up Fiddler and issue a Post request Using (EmployeeDBContext dbContext = new EmployeeDBContext())Īt this point build the solution. We will discuss the attribute in detail in a later article but for now to understand this attribute tells the Web API to get the employee data from the request body. The Employee parameter is decorated with the attribute. Notice that the Employee object is being passed as a parameter to the Post method. First, Include the following Post() method within the EmployeesController. Here, we want to add a new Employee to the Employees table. The Post Method in the Web API application allows us to create a new item. How to Implement the POST Method in Web API Application? Understanding the HttpResponseMessage return type in Web API.Testing the Web API Post method using Fiddler.Understanding the FromBody Attribute in Web API.How to Implement the POST method in Web API Application?.As part of this article, we are going to discuss the following pointers. Please read our previous article where we discussed how to Implement the GET Method in the WEB API application before proceeding to this article as we are going to work with the same application. In this article, I am going to discuss how to Implement the POST Method in Web API Application with one example. Data Structures and Algorithms Tutorialsīack to: ASP.NET Web API Tutorials For Begineers and Professionals How to Implement the POST Method in Web API Application.
