prism
prism copied to clipboard
Behaviors and state
Context
I want complex test fakes for APIs. I want write to affect reads, and I want to define the behavior of the API simulation. I’ve prototyped this in Golang and its very similar to Prism, except:
The CLI takes an additional file named operations.js. This file contained functions that have the the following signature:
(req, ctx) -> resp
The function is stateless. It is supplied the HTTP request and context and returns a HTTP response. I.e. it is a Lambda.
The context gives it access to state.
function listPets(req,ctx) {
var pets = ctx.db.list("pets/*")
return {statusCode: 200, body: {pets: pets}}
}