Add two numbers using post method
Loading
Add two numbers using post method
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mohammad HussainPosted Aug 24, 2023, 4:34 AM
http://localhost:YourPortNumber/api/add/addnumbersJaimin ShethiyaPosted Aug 22, 2023, 5:54 AM
Hello Vishakha,
You can try the below way.
[ApiController]
[Route("api/[controller]")]
public class CalculateController : ControllerBase
{
[HttpPost]
public IActionResult Post(AddRequest addRequest)
{
int result = Add(addRequest);
return Ok(result);
}
private int Add(AddRequest addRequest)
{
return addRequest.Num1 + addRequest.Num2;
}
}
public class AddRequest
{
public int Num1 { get; set; }
public int Num2 { get; set; }
}
Calling from the postman
Amit MohantyPosted May 3, 2023, 4:02 AM
Check this:
Or