This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Services and the fly likes RESTful URI naming questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "RESTful URI naming questions" Watch "RESTful URI naming questions" New topic
Author

RESTful URI naming questions

K Mansoor
Ranch Hand

Joined: Jan 10, 2006
Posts: 52
Folks- I'm confused about how to name a URI for this simple situation:

Let's say my website allows users to manipulate books (resources). I can use something like the following to add a book:


to delete:


and so on, now i have a menu item in the navigation bar which says, "Click here to create a book', what I want to do is to take the user to a page which displays a form, allowing the user to enter a new book info and when submit is pressed, the form will be POST'ed to:

Question is what URL to use for "Click here to create a book"?

is the following RESTful?
www.localhost:8080/bookz/book/new

Is there a convention for this?

Thank you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

/new is not RESTful because it's not addressing a resource.

I'd use something like /books/book/book-name, and I'd use a PUT rather than POST.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
K Mansoor
Ranch Hand

Joined: Jan 10, 2006
Posts: 52
can you please explain a bit the last element in /books/book/book-name (/book-name)? this can be an indication to the server to display a form to create a new book?

Thank you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

I thought you wanted to create the book, not display a form.
K Mansoor
Ranch Hand

Joined: Jan 10, 2006
Posts: 52
I want to display a form, which will allow user to enter information to create a book resource. Not sure how to name a url to display an 'Add a new book' form.

Thank you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

I'll let someone else handle that.

None of my RESTful APIs have a UI. Rather, I have a separate web app that handles the UI, and uses the UI-agnostic RESTful API (which has multiple clients including web apps, iPhone apps, Android, and so on).

Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1167
... the form will be POST'ed to www.localhost:8080/bookz/book


makes perfect sense to me.

Question is what URL to use for "Click here to create a book"?

As Bear pointed out, it seems to be an auxiliary url and doesn't seem to fall easily into this paradigm, as the url structure is about the resource. However, looking at rest/urls supports you all the way. It says -


Operate on the Collection
GET /people
return a list of all records
GET /people/new
return a form for creating a new record
POST /people
submit fields for creating a new record


How to create a REST Protocol is also useful.

Regards,
Dan

William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
K Mansoor
Ranch Hand

Joined: Jan 10, 2006
Posts: 52
Thank you, this is exactly what I needed.
Robert Morschel
Greenhorn

Joined: Oct 05, 2012
Posts: 1
I posted a set of guidelines that we use here: http://soaprobe.blogspot.co.uk/2012/10/soa-rest-service-naming-guideline.html

I hope that helps.

Robert
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: RESTful URI naming questions
 
Similar Threads
Invoking JAX-WS method from browser
Help submitting forms via SpringMVC and RESTful Web Service
Getting error when submitting form using SpringMVC and REST
getAttribute()
REST vs SOAP - stateful/stateless