Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>public HttpResponseMessage PostProduct(Product item) { //creates and adds an item to repository(db) item = repository.Add(item); //creates a new httpresponse var response = Request.CreateResponse(HttpStatusCode.Created, item); //creates new uri string uri = Url.RouteUrl("DefaultApi", new { id = item.Id }); //set header for new uri response.Headers.Location = new Uri(uri); return response; } </code></pre> <p>This lines will create a new RouteUrl -> basically a link for your response header.</p> <p>My advice would be that you should start with official documentation from here: <a href="http://www.asp.net/web-api" rel="nofollow">http://www.asp.net/web-api</a> , it worked for me. There are many things to be researched here: <a href="http://geekswithblogs.net/JoshReuben/archive/2012/10/28/aspnet-webapi-rest-guidance.aspx" rel="nofollow">http://geekswithblogs.net/JoshReuben/archive/2012/10/28/aspnet-webapi-rest-guidance.aspx</a></p> <p>There are too many examples to be posted in this answer, that may help you.</p> <blockquote> <p>· Response code: By default, the Web API framework sets the response status code to 200 (OK). But according to the HTTP/1.1 protocol, when a POST request results in the creation of a resource, the server should reply with status 201 (Created). Non Get methods should return HttpResponseMessage</p> <p>· Location: When the server creates a resource, it should include the URI of the new resource in the Location header of the response.</p> <pre><code>public HttpResponseMessage PostProduct(Product item) { item = repository.Add(item); var response = Request.CreateResponse&lt;Product&gt;(HttpStatusCode.Created, item); string uri = Url.Link("DefaultApi", new { id = item.Id }); response.Headers.Location = new Uri(uri); return response; } </code></pre> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload