tags:

views:

72

answers:

2

When you design URL schema for your application, which rules you use?

  • example.com/post/ or example.com/posts/ for list of posts
  • example.com/post/new/ or example.com/post/create/ for new post
  • example.com/posts/ + example.com/post/23/ or example.com/post/ + example.com/post/23/ for list and detail of post?
  • example.com/post/23 or example.com/post/23/ for details
  • example.com/post/edit/23/ or example.com/post/23/edit/ for editing.

I'm prefered: /post/ for list, /post/23/ for details, /post/23/edit/ for editing, just b/c I'm can very easy work with that URL by hand in browser location bar. I'm wrong? Suggest me, please.

Thanks.

+2  A: 

You should probably use the HTTP POST method when creating a new resource. So, for a new customer, you might POST to example.com/customer. Then if you want information on that customer, do a GET to example.com/customer/{your recently created customer id}. If you want all customers, do a GET to example.com/customer If you want to edit a customer you'll probably want to PUT to example.com/customer/{your customer id}

It seems that your fundamental issue is that you are dealing with is that you are specifying your action (or verb) in your URL. You don't need to do that. Instead of doing something like example.com/edit/23, you should use the HTTP PUT method with example.com/23 (or example.com/customers/23).

Have a look at http://stackoverflow.com/questions/2718204/what-is-restful-rest for a review on creating RESTful resources.

Have a look at http://stackoverflow.com/questions/630453/put-vs-post-in-rest for the difference between POST and PUT (edit and create).

For building more complex RESTful URLs, I generally refer to this presentation from the LinkedIn nerds.

labratmatt
Ok, thanks. My question was not exactly about how to use POST, PUT, etc. I'm just want to clarify how people design useful URL schemas (poor english do not allow explain this in question).But the presentation link from your answer is very help to me!
Zada Zorg
@Zada: I added a bit to my original post. It seems that the fundamental issue you're dealing with is that you don't need to use things like create or edit in your URL. You accomplish this by using different HTTP methods.
labratmatt
+1 if verbs are creeping into your URIs, you're probably not being restful.
nategood
A: 

I use:

  • GET /posts for list
  • GET /posts/new to get empty HTML form for 'static' sites only ('ajax' sites and 'stand-alone' clients don't need it)
  • POST /posts for create ('action' attr in previous form)
  • GET /posts/23 for detail (not for editing!)
  • GET /posts/23/edit to get filled HTML form with hidden '_method=PUT' field to emulate PUT in browsers
  • PUT /posts/23 for editing ('action' attr in previous form)
  • DELETE /posts/23 for deleting ('inline' HTML form with '_method=DELETE' to emulate)
  • POST /posts/23 for emulate PUT and DELETE in browsers

And I never use /posts/ or /posts/23/ because it makes hard (or dirty) to change response format. I can use /posts (synonym for /posts.html) for browsers , /posts.xml for XML services, /posts.json for 'ajax' data and /posts.smth_else for smth else :) in future. Also all of them may be static files (cache or archive) to free CPU and memory on high load.

VolCh