vendredi 2 janvier 2015

Web API return type difference : HttpResponseMessage and Customtype/string?

when we are using HttpResponseMessage as return type of a action/method.


we can able specify the cache duration. cache duration, maintain cache or not...under control of developer it.



public HttpResponseMessage Get()
{
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, "value");
response.Content = new StringContent("hello", Encoding.Unicode);
response.Headers.CacheControl = new CacheControlHeaderValue()
{
MaxAge = TimeSpan.FromMinutes(20)
};
return response;
}


Response Header:


HTTP/1.1 200 OK Cache-Control: max-age=1200 Content-Length: 10 Content-Type: text/plain; charset=utf-16 Server: Microsoft-IIS/8.0


when we using customtype/string as return type?,


Why HttpResponseMessage and why not directly return type is : string/Employee/IEnumerable ..ect ?





Aucun commentaire:

Enregistrer un commentaire