Skip to content

Instantly share code, notes, and snippets.

@netmilk
Last active August 29, 2015 14:07
Show Gist options
  • Save netmilk/b52a329b79ef307cbf70 to your computer and use it in GitHub Desktop.
Save netmilk/b52a329b79ef307cbf70 to your computer and use it in GitHub Desktop.
# stash object will automatically cache all responses under key with their name,
# parse JSON body and parse headers
{before, after, stash} = require 'hooks'
before "Machines > Machine > Retrieve a Machine", (transaction) ->
newId = stash['Machines > Machines collection > Create a Machine'].response.body._id
# replace id taken from blueprint with id from stash
transaction.request.uri = transaction.request.uri.replace '52341870ed55224b15ff07ef', newId
transaction.fullPath = transaction.fullPath.replace '52341870ed55224b15ff07ef', newId
# or better with some patchUri helper on transaction object
{before, after, stash} = require 'hooks'
before "Machines > Machine > Retrieve a Machine", (transaction) ->
newId = stash['Machines > Machines collection > Create a Machine'].response.body._id
transaction.patchUri _id: newId
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment