views:

39

answers:

1

Hey everyone,

I'm trying to do blog application and I want main page to have this URL: http://localhost/blog and posts to have URLs like this: http://localhost/blog/post-slug-name. So now I'm trying to understand how other actions should look like. Should it be something like this?

http://localhost/blog/post-slug-name/edit (GET/POST)
http://localhost/blog/post-slug-name (DELETE)
http://localhost/blog/create_new (GET/POST)

But I don't like to have "special case" create_new (because pattern is the same as for regular post). What is common way to do this?

A: 

If you have full control over how your server maps HTTP requests, you could use a POST to http://localhost/blog/post-slug-name/create to create a post using that slug name, returning a 201 Created status on success and a 409 Conflict if the page exists. The advantage of using a single create_new method is that it can handle conflict avoidance transparently and obviously.

Josh McFadden
But /post-slug-name/create doesn't make any sense as there's no slug name yet.
Vitaly
Well, in the url localhost/blog/post-slug-name/create, the string "post-slug-name" is just an argument to the "create" verb.If you don't want to pass a name into create, another option for consistency would be to put your verbs before the slug. "blog/create_new", "blog/edit/post-slug-name", "blog/view/post-slug-name", etc.
Josh McFadden
Okay, that was just nasty. Someone tell me how to monospace in a comment.
Josh McFadden
That's the thing: I don't want to have /view/post-slug-name (and I never saw such use anywhere). And there's no "post-slug-name" before post is actually created (how's it supposed to know what should the name be?).
Vitaly
Josh, thx for the answer. I sticked with this way for post: blog/post/post-name for viewing and blog/edit/post-name for editing.
Vitaly