Search code examples
restdomain-driven-designjson-api

JsonApi method calls


How may I include, using JsonApi, links to methods in my Rest API?, for example I have something like this:

POST api/v1/customer/1/deactivate
POST api/v1/customer/1/activate

To activate and deactivate a customer correspondingly. How they should be included (or not) in my data object? The specification does not include something like "methods" section for the data object.


Solution

  • Updating based on your change and based on guillaume31's answer.

    If it is truly an update to a resource then you should issue a PATCH to: api/v1/customer/1

    And with a jsonapi compliant body to update the resource:

    {
      "data": {
        "type": "customer",
        "id": "1",
        "attributes": {
            "status": "deactivated"
        }
      }
    }
    

    If the intent is to truly remove the resource then a delete may be more appropriate. Based on your description the PATCH may be the best path since the resource is still present and may be restored based on other calls