Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POSTing multiple documents #131

Closed
GavinJoyce opened this issue Sep 18, 2013 · 4 comments
Closed

POSTing multiple documents #131

GavinJoyce opened this issue Sep 18, 2013 · 4 comments

Comments

@GavinJoyce
Copy link
Contributor

It seems that the spec is setup to support POSTing multiple documents in one request : #66.

POST /photos
Content-Type: application/json
Accept: application/json

{
  "photos": [{
    "title": "Ember Hamster",
    "src": "http://example.com/images/productivity.png"
  }, {
    "title": "RestPack Armadillo",
    "src": "http://example.com/images/super-productivity.png"
  }]
}

I'd like to document these rules in the Creating a Document section.

Is it a MUST or a MAY that the server support creating multiple documents in this way? A MUST seems to make most sense. I'll submit a PR once this is clear.

@gr0uch
Copy link
Contributor

gr0uch commented Sep 18, 2013

I think this is correct, or at least it's how I implemented it in my json-api project. +1 to making it a MUST.

@zikes
Copy link

zikes commented Sep 18, 2013

Since the server MUST return a Location header for the newly created document, how should that be formatted in the case of multiple new documents? If it is a multi-document Location, how do you resolve that with an individually identifying href for each document in the response, since they MUST match?

@GavinJoyce
Copy link
Contributor Author

How about this: The server MUST return a Location header which represents the location of the newly created resource(s)?

For a single document:

HTTP/1.1 201 Created
Location: http://example.com/photos/12
Content-Type: application/json

{
  "photos": [{
    "id": "12",
    "href": "http://example.com/photos/12",
    "title": "Ember Hamster",
    "src": "http://example.com/images/productivity.png"
  }]
}

For multiple:

HTTP/1.1 201 Created
Location: http://example.com/photos?ids=12,13
Content-Type: application/json

{
  "photos": [{
    "id": "12",
    "href": "http://example.com/photos/12",
    "title": "Ember Hamster",
    "src": "http://example.com/images/productivity.png"
  }, {
    "id": "13",
    "href": "http://example.com/photos/13",
    "title": "RestPack Armadillo",
    "src": "http://example.com/images/super-productivity.png"
 }]
}

@steveklabnik
Copy link
Contributor

#202 is a superset of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants