Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm testing my Rest APIs on Postman, I don't know how to test an API with a POST method which takes an object as a parameter.

Some tutorial say that I should change the type on postman but I can't see this option, my postman control panel is the following(screen):

PostMan.png - Google Drive[^]

What I have tried:

My Rest Api :
C#
[System.Web.Http.HttpPost]
[System.Web.Http.Route("api/controllername/bookAvailability")]
public bool IsAvailable([FromBody] Book book)
{
    return _businessLogic.IsAvailable(book);
}
My API request:
http://localhost:8080/api/controllername/apiName
Where and how I should pass the entity book along with the request?
Posted
Updated 4-Dec-20 0:23am
v2

You are trying to pass the book details in the querystring. You need to pass it in the request body instead.

https://learning.postman.com/docs/sending-requests/requests/#sending-body-data[^]
 
Share this answer
 
Select the "Body" option which will reveal other options. You can select "x-www-form-urlencoded" and enter your values there, like

Id: 28
Title: Harry Potter


or (probably the better option) select "raw" and enter your data as json

{
    Id: 28,
    Title: "Harry Potter"
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900