Skip to content

Instantly share code, notes, and snippets.

@gabrielschulhof
Created October 25, 2016 13:43
Show Gist options
  • Save gabrielschulhof/44a70b1834db51419fb170e472f33554 to your computer and use it in GitHub Desktop.
Save gabrielschulhof/44a70b1834db51419fb170e472f33554 to your computer and use it in GitHub Desktop.
response payload calculation:
request.respond()
-> retrieve
-> OK, request.target.transform( request.target.properties, request.options )
-> update
-> OK, no payload [1]
-> delete
-> OK, no payload [1]
-> create
-> INTERNAL_SERVER_ERROR, reject( "Missing payload" )
request.respond( data )
-> data instanceof Resource
-> retrieve
-> OK, data.transform( data.properties, request.options )
-> update
-> OK, data.transform( data.properties, request.options ) [0]
-> delete
-> OK, data.transform( data.properties, request.options ) [0]
-> create
-> isValidResource( data )
-> RESOURCE_CREATED, data
-> resource not valid
-> INTERNAL_SERVER_ERROR, reject( "payload not a resource" )
-> data is plain object
-> retrieve
-> OK, request.target.transform( data, request.options )
-> update
-> OK, request.target.transform( data, request.options ) [0]
-> delete
-> OK, request.target.transform( data, request.options ) [0]
-> create
-> isValidResource( data )
-> RESOURCE_CREATED, data
-> resource not valid
-> INTERNAL_SERVER_ERROR, reject( "payload not a resource" )
[0] Should these be "no payload", even if data was given?
[1] Conversely to [0], should these be
request.target.transform( request.target.properties, request.options )
like the "retrieve" case?
@zolkis
Copy link

zolkis commented Oct 25, 2016

[0] Should these be "no payload", even if data was given?

Depends (based on the OCF spec): for update it MAY have data, for delete it doesn't have data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment