开发者

URL design: http://domain/app/document123/edit or http://domain/app/edit/document123?

Let's say I have an app and in that app I need to view and edit "documents". I was thinking of this URL design.

  1. To pull up the default view of document with the ID "x123":

    http://domain/app/document-x123

  2. To edit the same document:

    http://domain/app/document-x123/edit

  3. Delete

    http://domain/app/document-x123/delete

开发者_C百科

This is more from my thinking about a document as an object in an OO point of view (e.g. "object.Action()"). Is this a bad thing? Will I run into trouble? i.e. would it be better to have #s 2 and 3 as the following?

1.

http://domain/app/edit/document-x123

2.

http://domain/app/delete/document-x123


resource.action(id) feels more natural to me... so URL would be:

http://domain/app/documents/delete/x123


I like http://domain/app/document-x123/edit preference.

Take livejournal:

http://jwz.livejournal.com/

http://jwz.livejournal.com/profile

http://jwz.livejournal.com/calendar

(sorry jwz now when people google you this will come up.)

Or SO:

https://stackoverflow.com/users/208990/chris-simmons https://stackoverflow.com/users/208990?tab=activity#tab-top

Or the Twitter API:

http://apiwiki.twitter.com/Twitter-REST-API-Method:-POST-lists (http://api.twitter.com/1/user/lists.format)

To me, URL directories go from "general" to specific. Okay I'm at stackoverflow.com. Now I'm narrowing to "users". Now I've chosen a specific user. Now I'm looking at his activity.

Or "I want to access the twitter api. Now I want to move to a specific user. And now I want their lists".

So I think your intuition is fine, and it jives with what the rest of the intertubes does!


As qwerty put, I like the idea of Resource -> Action -> ID, but there is stuff to be said about both (in a more semantic way)

If you look at this url for a imaginary form-generator on a company's example.com:

http://example.com/form/view/1

You would most likely break it down into:

1) Use the Form Module
2) Use the View Module (or pass it as an action)
3) Pass the ID 1 to the module

I think this URL makes it look like you are passing the number 1 through a Form::View Module and getting the data out.

Now, if you look at this OTHER imaginary form-generator:

http://example.com/form/1/view

You can break it into this

1) Use the Form Module
2) Open up the data for ID 1
3) Preform the action 'view' on the ID 1

I think this URL makes it look like you are opening the data for the ID 1 and preforming and action on it.

I think both are equally valid, its mainly just in the semantics.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜