0

To create a document for a project in an REST API,

POST /projects/1234/documents

What status is expected to return if the project with id=1234 doesn't exist?


Related to this question, but dealing with POSTs, not GETs.

1
  • 404............ Commented Jun 9, 2018 at 1:48

1 Answer 1

1

Short answer: for most use cases similar to what you describe, 404.

More completely: the notion of "subresource" doesn't really exist in HTTP.

Yes, URI have a standard hierarchy of segments, and you can use relative resolution of dot segments to compute one URI from another. Those semantics do not translate into a hierarchy of resources.

/projects/1234/documents isn't a description of a path traversal, it's a key into a dictionary.

As far as HTTP is concerned, it is perfectly fine that /projects/1234/documents exists even though /projects and /projects/1234 do not.

Put slightly differently, the metadata in your response, which includes the status code, apply to the /projects/1234/documents resource, and not anything else.

Note that this goes both directions: not only does /projects/1234/documents not imply anything about /projects/1234, but it is also the case that it doesn't imply anything about /projects/1234/documents/5678.

Your best reference for getting your head around this is still going to be Fielding's thesis. It may also help to review RFC 7234

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.