REST managing state
Managing state in REST can be quite challenging. The change in state may trigger different validation and business rules used to process that payload. Rather than using complex logic we could use the resource paths to model the representation of each state.
Example
Modifying the pre-approval and post-approval of a workflow item. Below is an invoice that requires approval for payment.
Invoice creation state
POST /invoice
{
"invoiceId": 1000,
"invoiceDate": "02/04/2001",
"vendorName": "XYZ Industries Ltd",
"approving Manager": null,
"accountNumber": null
}
Invoice approval state
PUT /invoice/1000/approval
{
"invoiceDate": "02/04/2001",
"vendorName": "XYZ Industries Ltd",
"approving Manager": "Tom",
"accountNumber": null
}
Invoice payment state
PUT /invoice/1000/payment
{
"invoiceDate": "02/04/2001",
"vendorName": "XYZ Industries Ltd",
"approving Manager": "Tom",
"accountNumber": 6597465923056
}
Managing state in REST can be quite challenging. The change in state may trigger different validation and business rules used to process that payload. Rather than using complex logic we could use the resource paths to model the representation of each state.
Example
Modifying the pre-approval and post-approval of a workflow item. Below is an invoice that requires approval for payment.
Invoice creation state
POST /invoice
{
"invoiceId": 1000,
"invoiceDate": "02/04/2001",
"vendorName": "XYZ Industries Ltd",
"approving Manager": null,
"accountNumber": null
}
Invoice approval state
PUT /invoice/1000/approval
{
"invoiceDate": "02/04/2001",
"vendorName": "XYZ Industries Ltd",
"approving Manager": "Tom",
"accountNumber": null
}
Invoice payment state
PUT /invoice/1000/payment
{
"invoiceDate": "02/04/2001",
"vendorName": "XYZ Industries Ltd",
"approving Manager": "Tom",
"accountNumber": 6597465923056
}