nilportugues / php-json-api

JSON API transformer outputting valid (PSR-7) API Responses.
http://nilportugues.com
MIT License
70 stars 35 forks source link

Resource creation doesn't comply with the spec #36

Closed nilportugues closed 9 years ago

nilportugues commented 9 years ago

Bug for https://github.com/nilportugues/jsonapi-transformer/blob/master/src/Http/Message/ResourceCreatedResponse.php

:white_check_mark: If a POST request did not include a Client-Generated ID and the requested resource has been created successfully, the server MUST return a 201 Created status code.

:red_circle: The response SHOULD include a Location header identifying the location of the newly created resource.

:red_circle: The response MUST also include a document that contains the primary resource created.

:red_circle: If the resource object returned by the response contains a self key in its links member and a Location header is provided, the value of the self member MUST match the value of the Location header.

HTTP/1.1 201 Created
Location: http://example.com/photos/550e8400-e29b-41d4-a716-446655440000
Content-Type: application/vnd.api+json
{
  "data": {
    "type": "photos",
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "attributes": {
      "title": "Ember Hamster",
      "src": "http://example.com/images/productivity.png"
    },
    "links": {
      "self": "http://example.com/photos/550e8400-e29b-41d4-a716-446655440000"
    }
  }
}
nilportugues commented 9 years ago

Fixed by https://github.com/nilportugues/jsonapi-transformer/commit/7494beb49bf7949062aaef13cc65cb1080597c60