rest - What is the appropriate response for a broken link in the request entity? -


say have restful api binds user company:

put http://example.com/users/john.smith

{   "company": "http://example.com/companies/nintendo" } 

but referenced company not exist (possibly due race condition, possibly due user error). operation cannot complete because database requires foreign keys point existing rows. appropriate response code , why?

i return http 400 - bad request, adding in response body hint (e.g. nintendo not valid option). it's not 404 - not found error, since url , resources referenced in correct.

as side note body of request

{   "company": "http://example.com/companies/nintendo" } 

i expect users pass name, or id company, not whole uri. add more complexity without possibly gaining anything. imagine user passing valid company name, e.g. sega, in uri has typo, e.g. comppanies. i'm guessing backend try access uri, and, failing that, return error. well, could, me seems making both yours , users life difficult.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -