Skip to content

Instantly share code, notes, and snippets.

@jacksmith15
Created May 22, 2019 11:02
Show Gist options
  • Save jacksmith15/b66abce0b5837d946a1e69708efd8df0 to your computer and use it in GitHub Desktop.
Save jacksmith15/b66abce0b5837d946a1e69708efd8df0 to your computer and use it in GitHub Desktop.

Referral Status API

Handle status transition logic as state in GET

GET /referral/{id}/status

{
    "data": {
        "id": "2b074729-376b-4dfa-963c-39ddbc6a2a2c",
        "code": "draft",
        "display": "Draft",
        "system": "referral_status",
    },
    "meta": {
        "valid_next_statuses": {
            "cancel": "entered-in-error",
            "submit": "submitted",
            "current": "draft"
        }
    }
}

PUT /referral/{id}/status

{
    "status": currentStatusBody["meta"]["valid_next_statuses"]["cancel"]
}
  • Avoids needing business logic for transitions in FE

  • Stateless (RESTful)

  • Need to agree on what to call the actions (cancel, submit, current), should these labels be exposed or just documented?

JSONAPI version:

{
    "data": {
        "id": "2b074729-376b-4dfa-963c-39ddbc6a2a2c",
        "type": "status",
        "attributes": {
            "code": "draft",
            "display": "Draft",
            "system": "referral_status"
        }
    },
    "meta": {
        "valid_next_statuses": {
            "cancel": {
                "type": "concept",
                "id": "ba091020-71b3-49d3-af23-a923c2f1378e",
            },
            "submit": {
                "type": "concept",
                "id": "e808f0f0-f625-4e30-a5e9-e61d287bb935",
            },
            "current": {
                "type": "concept",
                "id": "37945ee8-0bfd-4758-acdc-5977ce6616f9",
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment