Hacker News new | ask | show | jobs
by durana 5904 days ago
If I understand your comment correctly, I believe the API already works this way, except instead of using PUT, it uses POST for creating new records and zones. To create a record, a client would do a POST with the record to create in JSON as the request body.

Is there some reason to use PUT over POST in this case? By my understanding, POST is typically used to create new resources and PUT is used to updated existing resources.

Also, I can see now that the doc is pretty unclear on how the API expects data to be sent in a request's body. I'll be sure to fix that!

Thank you for your comment and yes I'm in need of more beta testers! Please e-mail me. My e-mail address can be found under my HN account.

1 comments

Well yes technically the API does "work." The problem is that most people are coming from rails land (which is also where I'm from, btw) and over there, they have implemented "REST" as POST=create and PUT=update. This doesn't even really make sense in rails actually.

For a proper PUT request you have to specify the full body of the resource to be "put." It literally is supposed to be telling the server, "hey, put this thing I'm giving you at this url." For that to work you have to actually be delivering the thing, and in rails with PUT you are just submitting form data, which is a set of paramater name/value pairs (this is also what's going on with POST but in that case it's ok). This mistake derives mostly from the fact that rails works off of forms, and form data is always passed in parameter pairs, so you are never passing a full resource to the server. I'm still not sure why they don't just do create and update with POST though.

Anyway yes, your API will work fine. You can define it any way you want, and you don't even have to stick to the original intention of the HTTP verbs. It's just that to me, create should be idempotent in the case of creating zones and records, so why not use the idempotent http verb?

I highly recommend this: http://jcalcote.wordpress.com/2008/10/16/put-or-post-the-res... and this: http://www.elharo.com/blog/software-development/web-developm...