Ashok kumar
Ashok kumar

Reputation: 1611

How to use Postman for FromUri request parameters?

I have written the below simple Web API method.

[HttpGet]
[HttpPost]
public int SumNumbers([FromUri]Numbers calc, [FromUri]Operation op)
{
    int result = op.Add ? calc.First + calc.Second : calc.First - calc.Second;
    return op.Double ? result * 2 : result;
}

Below is the model class for Numbers:

public class Numbers
{
    public int First { get; set; }
    public int Second { get; set; }
}

Below is the model class for Operation:

public class Operation
{
    public bool Add { get; set; }
    public bool Double { get; set; }
}

Now, I am not understanding how to use Postman to check this Web API method.

I have tried like below, but not working. I am not getting any error, but I am not getting response. Can anyone help me?

enter image description here

Upvotes: 0

Views: 2990

Answers (1)

Alex.U
Alex.U

Reputation: 1701

You're setting the values on the header but using the URI in your code. You would need either to change your code OR the way you send the request with Postman.

As far as I can see you'd need to add the values to your URI as part of the query string:

http://localhost:29844/api/bindings/SumNumbers?first=10&second=20&add=true&double=false

Have a look at this

Upvotes: 2

Related Questions