aspose file tools*
The moose likes Web Services and the fly likes Make the method an optional parameter in the URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Make the method an optional parameter in the URL" Watch "Make the method an optional parameter in the URL" New topic
Author

Make the method an optional parameter in the URL

Andrej Avoine
Greenhorn

Joined: Feb 05, 2013
Posts: 2
Hello,

I've recently read the following :


When a client supports limited HTTP methods

It is common to see support for GET and POST and not PUT and DELETE.
To maintain the integrity of the four HTTP methods, we suggest you use the following methodology commonly used by Ruby on Rails developers:

Make the method an optional parameter in the URL.

Then the HTTP verb is always a GET but the developer can express rich HTTP verbs and still maintain a RESTful clean API.

Create /dogs?method=post
Read /dogs
Update /dogs/1234?method=put&location=park
Delete /dogs/1234?method=delete


My questions is, how do I implement with javax.ws.rs when I want the following Dog creation method being accessible from HTTP GET "/dogs?method=post":

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41574
    
  54
I think you shold take a step back and ask *why* you want to do that. What kind of client do you envision that can't use some of the HTTP methods?


Ping & DNS - my free Android networking tools app
Andrej Avoine
Greenhorn

Joined: Feb 05, 2013
Posts: 2
I think you shold take a step back and ask *why* you want to do that. What kind of client do you envision that can't use some of the HTTP methods?



The reason why is our old API, which isn't RESTFul at all: "GET /createNewCats.do" and "POST /createNewCats.do" does exactly the same thing.

Today, I'm developing a new API, which I'd like to be RESTFul. My problem is: I'd like to make the functions of the new API accessible to the users of the old API (who refuse to use HTTP methods) while keeping the new code clean.

The dirty solution would be to have "POST /dogs" for new users and "GET /newDogs" (which would be the RESTless clone oh the previous) for the old users.

A little cleaner solution would be the possibility to override the method to make the new API more flexible: "POST /dogs" for new users and "GET /dogs?method=post" for the old ones.

Now I would like to know which would be the better way to implement this "?method=post":

- Maybe some way of overriding annotations?
- Ready to use solutions?
- Maybe some examples?
- Other ideas?
 
wood burning stoves
 
subject: Make the method an optional parameter in the URL