Like Peter Griffin said the bird is the word, I say the VERB is the word. What I’m I talking about? HTTP Verbs.
I have been recently playing with Windows Azure Mobile Services commonly called ZUMO. In doing so I ran into a bit of a snag. I was trying to do CRUD operations from an MVC 4 app when i kept getting an error on updates. As many people know the typical mapping for REST APIs is something like this:
Read: HTTP GET Insert: HTTP POST Update: HTTP PUT Delete: HTTP DELETE
While I had no issues inserting or reading the update action was failing with the following error “{“MethodNotAllowed“}. After some digging I was able to spot the issue. The ZUMO REST API is expecting the PATCH Verb instead of PUT.
I replaced the following:
var request = new HttpRequestMessage(HttpMethod.Post, BaseAddress);
with
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("X-ZUMO-APPLICATION", ApplicationKey);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var request = new HttpRequestMessage(new HttpMethod("PATCH"), BaseAddress + contact.id);
That little tweak did the trick!
Hope this helps others playing with Windows Azure Mobile Services too. If you haven’t go ahead and give it a try đŸ™‚