I am having trouble understanding http://jsonapi.org/. Say, I have the following endpoints in my API for authors and articles.

/authors

/authors/:id/articles

If I wanted to fetch the details for a single article, I can use

/authors/:id/articles/:id

which returns data that looks like

{
  "id": "1",
  "type": "articles",
  "data": {
    "attributes": {
      "title": "Programming in javascript.",
      "body" : "Some long text here..."
    },
    "relationships": {
      "author": {
        "data": {
          "id": "2",
          "type": "authors"
        },
        "links": {
          "self": "http://api.com/authors/2"
        }
      }
    }
  }
}

Now, if I want to update this article and change the author, the spec says I should use a PATCH. Should this PATCH request be made to

/authors/:id/articles/:id

/authors/:id/articles/:id/relationships/author

or

/articles/:id

/articles/:id/relationships/author

up vote 1 down vote accepted

If you want to change who the author is, that's a relationship on the article. You would patch /articles/:id and include the new author, as per the spec.

  • Please remove the trailing period from the link :) – Sam Chats Aug 9 at 21:16
  • @SamChats Fixed! – Eric Stein Aug 9 at 23:34

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.