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?

3 Answers 3

2

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.

1
  • That's where my mind was leading but it's reassuring to see other people agree :) Thanks. Aug 17, 2010 at 16:19
2

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

GET http://example.com/posts/createform
1
  • 1
    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
    Aug 17, 2010 at 19:07
0

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.

1
  • Yes, but what about displaying the form for inserting the new post? That's what the question is about.
    – Skilldrick
    Aug 17, 2010 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.