RESTful API design

8 views
Skip to first unread message

Scott Wilson

unread,
Apr 9, 2012, 9:33:32 AM4/9/12
to widge...@googlegroups.com
Hi all,

I've just had a look at this:

http://code.google.com/p/edukapp/source/browse/trunk/rest%20api%20calls%20examples

And some implementation here:

http://code.google.com/p/edukapp/source/browse/trunk/src/main/java/uk/ac/edukapp/servlets/WidgetServlet.java

This isn't good RESTful API design and needs a serious rethink. If we're encoding HTTP methods into URLs we're doing it wrong!

So instead of creating URLs with "GET" and "PUT" in them (etc), we should just use the HTTP verbs in the request and respond appropriately.

(I imagine this is to get around some implementation issue with the urlrewriter or something. If so, tough, we have to make it work properly)

If no-one object I'll make a start on refactoring this...

S

Lucas Anastasiou

unread,
Apr 9, 2012, 10:31:27 AM4/9/12
to widge...@googlegroups.com
Hi Scott,

I totally agree - this is a bad implementation of REST.
I just chose to do it that way since using doPut() doDelete() of servlets is kind of difficult to capture the request parameters,
and since we are not using Jersey or RESTlet this seemed -at the time- as the most straightforward way to implement it.

I think we should move everything to a web api framework (such as RESTlet or Jersey) instead of implementing the 
doGet,doPost,doPut, doDelete methods in each servlet. What do you think, does it worth the effort or is it an overkill?

Best,
Lucas

Scott Wilson

unread,
Apr 9, 2012, 11:00:12 AM4/9/12
to widge...@googlegroups.com
On 9 Apr 2012, at 15:31, Lucas Anastasiou wrote:

Hi Scott,

I totally agree - this is a bad implementation of REST.
I just chose to do it that way since using doPut() doDelete() of servlets is kind of difficult to capture the request parameters,
and since we are not using Jersey or RESTlet this seemed -at the time- as the most straightforward way to implement it.

You generally can't send any parameters with PUT or DELETE - this is how its implemented in most browsers. For PUT you are supposed to put the modified resource content in the request body; for DELETE its assumed you want to just delete the identified resource, so there are no requirements to send parameters.

So basically you have to redesign an API around these constraints.


I think we should move everything to a web api framework (such as RESTlet or Jersey) instead of implementing the 
doGet,doPost,doPut, doDelete methods in each servlet. What do you think, does it worth the effort or is it an overkill?

I think its worth doing perhaps later on  - we can sketch out the API for now using Servlets for now. I'll do a quick refactor and report back...
Reply all
Reply to author
Forward
0 new messages