Reputation: 111
I'm trying to pass data in POST request. In swagger, which runs automatically, they are passed, if you use POSTMAN or other client parameters are not passed. Thank you in advance for your help
[ApiController]
public class UsersController
{
DatabaseContext context = new DatabaseContext();
[Route("loginUser")]
[HttpPost]
public string LoginUser(string email, string password)
{
# some logic
}
}
Upvotes: 1
Views: 2252
Reputation: 8312
You can convert your parameters for your API to a strongly defined Model
:
public class MyData
{
public string email {get;set;}
public string password {get;set;}
}
And then you can use the [FromBody] attribute to get your values in your API method:
[ApiController]
public class UsersController
{
DatabaseContext context = new DatabaseContext();
[Route("loginUser")]
[HttpPost]
public string LoginUser([FromBody]MyData data)
{
string email=data.email;
string password=data.password;
# some logic
}
}
Upvotes: 2
Reputation: 1
We need to pass the data using params section from postman screenshot
Upvotes: 0