Mehrdad Mehrdad - 2 years ago 91
HTTP Question

HTTP status code for associating resources

Suppose I have 2 resources (models) in my service:


When a user sends a post request to the rest API

with data like
[courseId => 2]

It associates
with id 1 to a
with id 1.
What should status code be for representing this update?

Should I return

Also what do you suggest for response body? The updated
along with associated

Answer Source

I am not sure about the big picture of your API. It somehow seems that a specific course (the ID of which you provide in the request body) should be its own resource.

However given the description, I see two possibilities:

1) Create a new resources, such as


This resource could for example be used to issue a later DELETE request. In this case you can return 201 and include a Link to the newly created resource.

2) If there is no such resource, 200 seems to be the only applicable positive response.

Option 1 seems preferable to me.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download