Skip to content

Instantly share code, notes, and snippets.

@AlexZeitler
Last active January 22, 2017 10:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexZeitler/7fd2a1ba8130d306526bf836b46b0813 to your computer and use it in GitHub Desktop.
Save AlexZeitler/7fd2a1ba8130d306526bf836b46b0813 to your computer and use it in GitHub Desktop.
hypermedia api flow
'use strict';
const api = require('./lib')
const customer = {
companyName1: 'PDMLab'
}
api
.establishContext([
'http://localhost:3000', // customer service root doc based on e.g. Siren
'http://localhost:3001' // order service root doc on e.g. Siren
])
.then(() =>
api
.new('application/vnd.customer+json', customer)
.then(customer =>
api
.new('application/vnd.order+json', {
customer: customer,
items: ['MBP', 'MBA', 'iPad']
})
.then(order => console.log(order))))
{ customer:
{ companyName1: 'PDMLab',
id: '01a5a4c9-6727-401c-8d3a-c05047d3a0f0' },
items: [ 'MBP', 'MBA', 'iPad' ],
id: '0fff8964-2e02-4865-b39a-aede0ce7f759' }
@MikeBild
Copy link

MikeBild commented Sep 4, 2016

Exciting! Here are some abstract bullets to create and consume hypermedia IMHO tastier.

  • the media type describes the contract
  • the contract is available via an endpoint
  • a contract contains the current state and all possible state transition operations
  • an operation response contains a contract which describe the new state or an location to query the new state
  • "live" contract introspection queries can be used to define flow state transitions
  • A "flow" is a declarative and logically sequential description of stepwise operations supported by the participating contract description
  • A "flow step" is a declarative operation description wich has an success and an failure output
  • A "flow" can be described by a shorthand notation (DSL) and should be transform to an AST/Executable via transpiler (eg. Babel)
  • ...

e.g. //localhost:3000 (all following endpoints can be determined by introspection)

customer(customer: {companyName1: 'PDMLab'}) catch customerFailure
order(items: ['MBP', 'MBA', 'iPad']) catch orderFailure
checkout(address: {...}) catch checkoutFailure

nesting is possible

customer(customer: {companyName1: 'PDMLab'})
    order(items: ['MBP', 'MBA', 'iPad'])
        checkout(address: {...}) catch checkoutFailure
    catch orderFailure
catch customerFailure

@AlexZeitler
Copy link
Author

AlexZeitler commented Sep 12, 2016

Points 1 + 2 of your suggestions already work in the PoC.

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