The process of setting values to the parameter of WEB API
method is called parameter binding and In parameter binding, it takes an HTTP
request and converts it into .Net types so that you can able to set action
parameters.
The generic rules or default
behavior of WEB API parameter binding:
·
If parameter is simple .Net primitive types (integer, bool,
decimal etc.) it try to get from HTTP Request URI.
·
If parameter is Complex Type, It read the value from http request
http request body.
Here is HTTP Request URI, Which is
being used to call to Web API to get project information.
public class ProjectApiController : ApiController
}
[HttpGet]
}
By using [FromUri] attribute, the parameter value should be read
from Http Request Uri.
[HttpGet]
[HttpGet]
return Repository.GetProperty(projectId);
}
By default, the value of complex type of parameter should read
from Body but you can set value from Uri by using [FromUri] attribute
SearchParameter as complex type:
public class SearchParameter
{
public int PageNumber
{ get; set; }
public int PageSize
{ get; set; }
public string Name { get; set; }
public string Location
{ get; set; }
}
[HttpGet]
public HttpResponseMessage Get([FromUri]SearchParameter filter)
{
}
Other related topics:
- ASP.NET Web API Caching
- Steps
To Improve ASP.NET Web API Performance
- 4
Simple Steps To Create ASP.NET Web API
- Parameter
Binding or Model Binding in ASP.NET Web API
- The
Life-cycle of an ASP.NET Web API
Thanks
for visiting!!
No comments:
Post a Comment