ASP.NET Web API is a .net framework that makes it easy to build HTTP
services that reach a broad range of clients, including browsers and mobile
devices. ASP.NET Web API is an ideal platform for building RESTful applications
on the .NET Framework.
class UserScreenData
}
In this blog, we will discuss about 4 techniques to quickly improve the
ASP.NET Web API performance.
1.
JSON serializer over XML:
JSON serializer use
JSON Formatter and by default Web API provides media-type formatters for both
JSON and XML.A media type formatter is used to read CLR objects from an HTTP
message and write the CLR object in HTTP message body.
JSON serializer is
highly recommend and it very faster compare to other Serlializer like XML.
2.
Asynchronous Task Based
WebAPI :
Async Web API action help to increase the
number of concurrent HTTP requests Web API can handle. We can implement asynchronous programming for web api controller by using keywords async, Task, await
public class UserController : ApiController
{ public async Task<IHttpActionResult> Read()
{
var data = await _db.UserMaster.ToListAsync();
return Ok(data);
}
}
3. Cache Data:
Web API does
not provide the output Caching attribute to cache web api response but you can
Cache data in memory to process same future request without hitting database
and it improve the performance of ASP.NET Web API and Microsoft provides the System.Runtime.Caching library
for memory caching. More information about web api caching
4.
Multi ResultSets:
Web API should return as many objects as you can in
one Web API request and combining objects into one aggregate object and It
reduce the number of HTTP request to web API
Example : Aggregate
Object ‘UserScreenData’
class UserScreenData
{
public List<State> States { get; set; }
public List<Country> Countries { get; set; }
}
Web API Method to
return Aggregate object
public async Task<IHttpActionResult>
GetScreenData()
{
UserScreenData screen = new Controllers.UserScreenData();
screen.State = await _db.State.ToListAsync();
screen.Countries
= await _db.Country.ToListAsync();
return Ok(data);
Other ASP.NET WEB API 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!!
3 comments:
Great post,Thanks for sharing
.Net Online Training Bangalore
Hire dot net developers for all your web applications development, CMS customisations and migrating your existing apps to the .NET Platform seamlessly now.
Great info. thnx
Is there a way to measure times on each step, or at least of some of them?
Post a Comment