0

When building a RESTful API over HTTP, what is considered to be correct when wanting to add resources to a nested relationship (e.g. a user with posts)?

Post the new resource to:

/users/$user_id/posts/

Or post the new resource to:

/posts/

And setting the user ID in the POST data?

Sorry, but there's so much FUD about REST APIs, I'm still trying to figure a lot of things out.

Thanks in advance!

K.

Braek
  • 581
  • 5
  • 22
  • 1
    Neither is *technically* correct. If you want the by-the-book definition of how to add a user post to a user resource, you would follow the links provided to you by the server that were defined for that relation (e.g., the "posts" relation). And that would depend on the media type you're sending back and forth. I guess my question is... if you're delving into REST, how much do you *really* want to know about what the REST style really is? :) – Jonathan W Oct 14 '14 at 17:59

1 Answers1

0

I would put it in the

/users/$user_id/posts/

seems more correct,but if the userid data is sensitive i would use

/user/posts

and pass the $user_id in the body

arnabmitra
  • 903
  • 9
  • 19