Created
December 8, 2017 10:34
ReST API Workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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