Reputation: 2818
When you design URL schema for your application, which rules you use?
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.
Upvotes: 5
Views: 4513
Reputation: 369
I use:
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.
Upvotes: 0
Reputation: 1841
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 what is RESTful/REST for a review on creating RESTful resources.
Have a look at 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.
Upvotes: 4