0

I have a java based rest server, and my clients will be using Ruby mostly.

What is considered the best practice for URL structure?

This is for JSON only.

Say this is a blog application:

e.g.:

Get all posts:

 GET http://www.example.com/api/v1/posts.json

Delete post with id 1:

DELETE http://www.example.com/api/v1/posts/1.json

What about embedded collections like:

Get all comments for post 1:

GET http://www.example.com/api/v1/posts/1/comments.json

View post 1's comment with id 1:

GET http://www.example.com/api/v1/posts/1/comments/1.json

Is there a document that goes over this somewhere? Something fairly "official"?

Srinivas
  • 1,780
  • 1
  • 14
  • 27
loyalflow
  • 14,275
  • 27
  • 107
  • 168

3 Answers3

0

Apigee has a free e-book on RESTful API design. You have to supply an email address to get it:

http://offers.apigee.com/api-design-ebook-rr/

You're going to find this is a matter of opinion, with no official spec, but your URLs look good to me, and would be in accordance with the guidelines in that book. The possible exception being the last. If 1 is the unique ID of a comment, /posts/1/ may not be necessary.

Jimothy
  • 9,150
  • 5
  • 30
  • 33
0

You could start with the paper that coined REST and look at the URI section: http://www.ics.uci.edu/~fielding/pubs/dissertation/evaluation.htm#sec_6_2

Bob Aman's well-regarded 2nd answer to this SO question gives detailed guidance: How to create REST URLs without verbs?

Community
  • 1
  • 1
Will
  • 6,601
  • 3
  • 31
  • 42
0

Correctly using the HTTP protocol is the best idea. Read some about the url versioning. http://blog.steveklabnik.com/posts/2011-07-03-nobody-understands-rest-or-http

Leszek Andrukanis
  • 2,114
  • 2
  • 19
  • 30