DarioN1
DarioN1

Reputation: 2552

c# .Net WebApi - Receive parametes from POST and Uri

Just a simple question:

Is is possible to extend this webapi method in order to receive json paylod as now and a parameter from uri ?

This is the code:

    [Authorize]
    [Route("save")]
    public IHttpActionResult api_Offert_SAVE(reqOffertSave req)

In this moment the webapi method url is something like this:

http://localhost/save

I want to add a new parameter in order to be able to call the method in this way:

http://localhost/save?log=true

How can I do this?

Thanks

Upvotes: 0

Views: 50

Answers (1)

manish
manish

Reputation: 1458

you can use [FromBody] and [FromUri] for the parameters you want from json payload and for the parameters you want from uri respectively

[Authorize]
[Route("save")]
public IHttpActionResult api_Offert_SAVE([FromBody] reqOffertSave req, [FromUri] bool log) {
   /* rest of your API */
}

Upvotes: 3

Related Questions