Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ReST API Workflow
// Create an order.
POST /orders
request = {
title: 'TITLE',
description: 'DESCRIPTION'
}
response = {
id: 'ORDER_ID',
title: 'TITLE',
description: 'DESCRIPTION',
state: 'created',
availableTransitions: [
'validated',
'canceled'
]
}
// Validate an order
PATCH /orders/ORDER_ID
request = {
state: 'validated',
validationInfo: {
validatedAt: '2018-01-01',
validatedBy: 'Jesus',
validatedWith: 'Bread&Wine'
}
}
state_machine = OrderStateMachine(order)
state_machine.processUpdate(request.data)
class StateMachine(object):
def processUpdate(self, data):
state = self._getCurrentState()
return state.processUpdate(data)
class StateCreated(object):
def processUpdate(self, data):
// Checks properties `creationInfo` ...
data = OrderCreatedSerializer().deserialize(request.data)
// do stuff
return OrderValidatedSerializer().serialize(self._order)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment