views:

46

answers:

3

I understand most of how a RESTful site design should function, but in implementing a blog cannot decide the best way to present the form to insert a new blog post. Would example.com/posts/create be reasonable? This feels like the "create" is not restful, like it's putting information into the URI that should be simply represented by PUT/POST.

How would others do this?

+1  A: 

Have a look at Rails Routing for the Rails view on this.

Verb   URL            Controller  Action   Used For
GET    /photos/new    Photos      new      return an HTML form for creating a new photo
POST   /photos        Photos      create   create a new photo

So, in your situation, GET /posts/new to get the new post form, but POST /posts to create a new post.

The point is, you're POSTing a new blog post, but to do that you need to GET the form that will enable you to do this. In a way, the new blog post form is just another (static) resource.

Skilldrick
That's where my mind was leading but it's reassuring to see other people agree :) Thanks.
tsv
A: 

Use a POST to submit the information for the insert, and then have the page do a redirect to the with the new ID in the URL. You don't want to have the new information on the URL since a user refreshing the URL will post twice.

Carter
Yes, but what about displaying the form for inserting the new post? That's what the question is about.
Skilldrick
+1  A: 

If you don't like the way that URL feels, then change it to:

GET http://example.com/posts/createform
Darrel Miller
I think this hits the nail on the head. You just changed the verb `create` for the noun `createform`. Indeed, just `/posts/form` works well too, I guess. But please remember to allow clients to discover the URI of the form somewhere else!
mogsie