Asked by:
Web api HEAD,MERGE and OPTIONS

Question
-
User-148788041 posted
fFriend
I had written code for GET,PUT,PATCH AND DELETE. it is working fine and i am ble to consume the same Web Api
How to write Web api for
- HEAD
- OPTIONS
- MERGE
and consume the same web api.
Anand
Sunday, October 7, 2018 4:48 PM
All replies
-
User-271186128 posted
Hi Guhananth,
How to write Web api for
- HEAD
- OPTIONS
- MERGE
and consume the same web api.
Please refer to the following code:
Api controller code:
public class ValuesController : ApiController { [HttpHead] public IEnumerable<string> Head() { return new string[] { "value1", "value2" }; } [HttpOptions] public string Option(int id) { return "option value " + id.ToString(); } [HttpPatch] public string Patch(int id) { return "patch "+ id.ToString(); }
JQuery script to consume above methods:
<script type="text/javascript"> $(function () { $("#btnoption").click(function () { //// Consume the Option method. //$.ajax({ // url: '/api/values/option?id=6', // method: 'OPTIONS', // contentType: "application/json; chartset=utf-8", // dataType: "json", // success: function (data) { // //debugger // alert(data); // }, // error: function (error) { // alert("error"); // } //}); ////consume the Head method. //$.ajax({ // url: '/api/values/option', // method: 'HEAD', // contentType: "application/json; chartset=utf-8", // dataType: "json", // success: function (data) { // debugger // alert("success"); // }, // error: function (error) { // alert("error"); // } //}); ////consume the Patch method. $.ajax({ url: '/api/values/Patch?id=4', method: 'Patch', contentType: "application/json; chartset=utf-8", dataType: "json", success: function (data) { alert("success " + data); }, error: function (error) { alert("error"); } }); }); }); </script>
More details about these methods, please check this article:
HEAD: The HEAD method asks for a response identical to that of a GET request, but without the response body.
OPTIONS: The OPTIONS method is used to describe the communication options for the target resource.
PATCH: The PATCH method is used to apply partial modifications to a resource.
Best regards,
DillionMonday, October 8, 2018 5:45 AM -
User-148788041 posted
Dillon,
i am looking for HEAD,PATCH,MERGE,OPTIONS in Web Api.
Please provide code for all above verbs and consume it.
Wednesday, October 10, 2018 5:54 PM -
User475983607 posted
i am looking for HEAD,PATCH,MERGE,OPTIONS in Web Api.
Please provide code for all above verbs and consume it.
The example code above shows Web API and code that consumes Web API. This is not the only post we the community has provided this same information even different API consumers. I'm not sure what else we can do for you.
As far as I know, MERGE is not a valid HTTP Method so I'm not sure where you are coming up with MERGE.
Wednesday, October 10, 2018 6:41 PM -
User-271186128 posted
Hi Guhananth,
i am looking for HEAD,PATCH,MERGE,OPTIONS in Web Api.
Please provide code for all above verbs and consume it.
Since MERGE is not one of the verbs that is defined in the HTTP specification [RFC2616], using the MERGE verb might not flow through network intermediaries as seamlessly as methods that are defined in the HTTP specification. And, a MERGE request is similar to a POST request, so, if you want to update the data, I suggest you could try to use Post method to update the data.
More details about Merge, please refer to the following articles:
https://msdn.microsoft.com/en-us/library/dd541276.aspx
As for the used of the HEAD,PATCH,OPTIONS methods, please refer to my precious reply.
Best regards,
DillionThursday, October 11, 2018 3:08 AM