When do I use the first action?
public HttpResponseMessage Put(HttpRequestMessage message)
{
}
I nearly always see only this way. Maybe because it easily maps to a restfull url?
public HttpResponseMessage Put(int id)
{
}
The HttpRequestMessage parameter is automatically bound so that you can get hold of request information in your controller method if you need to (source). If you don't need to access it, omit it. If you need to pass an id , you will need: public HttpResponseMessage Put(HttpRequestMessage message, int id)
The HttpRequestMessage class contains headers, the HTTP verb, and potentially data. This class is commonly used by developers who need additional control over HTTP requests. Common examples include the following: To examine the underlying SSL/TLS transport information. To use a less-common HTTP method.
Typically, a series of message handlers are chained together. The first handler receives an HTTP request, does some processing, and gives the request to the next handler. At some point, the response is created and goes back up the chain. This pattern is called a delegating handler.
To reiterate, you are allowed to pass only one value (simple or complex type) as parameter to a Web API controller method when using the [FromBody] attribute. You can pass any number of parameters using the [FromUri] attribute but that is not the ideal solution in our case.
public HttpResponseMessage Put(HttpRequestMessage message)
is equivalent to:
public HttpResponseMessage Put()
The HttpRequestMessage
parameter is automatically bound so that you can get hold of request information in your controller method if you need to (source). If you don't need to access it, omit it.
If you need to pass an id
, you will need:
public HttpResponseMessage Put(HttpRequestMessage message, int id)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With