kamikat / moshi-jsonapi

JSON API v1.0 Specification in Moshi.
MIT License
156 stars 34 forks source link

Generate relationships string to create to-many relationships #31

Closed koraykoska closed 7 years ago

koraykoska commented 7 years ago

This example is from the JSONAPI documentation:

POST /articles/1/relationships/comments HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": [
    { "type": "comments", "id": "123" }
  ]
}

which is an example to wire up a to-many relationship.

As well as the following to removerelationships:

DELETE /articles/1/relationships/comments HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": [
    { "type": "comments", "id": "12" },
    { "type": "comments", "id": "13" }
  ]
}

Is it possible to generate this sructure with moshi-jsonapi? If not we should consider adding it because this is an essential feature to generate relationships with jsonapi.

If it is, how would we generate a Retrofit request which creates a relationship or removes it? Because in this case the response body of the server will be empty so we can't have a Call<Relationship> or whatever...

kamikat commented 7 years ago

It's now available on 3.0.0, and I've just add some test cases for this feature. Thanks a lot!