Shared env
Object
If you want to provide and shared global object in form of a known interface,
you can provide env
to the op definition. env
object will default extend
the HttpServerShim
and extend the given interface on top.
import { httpOp, httpReturn, as } from 'ts-basis/nodejs'
interface MyInterface {
someSharedKeyValueMap: {
[key: string]: any
}
}
export const myApiFunction = httpOp(
{
env: as<MyInterface>(),
params: {},
returns: httpReturn<{ data: string }>(),
},
async (op, env) => {
// env is (HttpServerShim & MyInterface) type
// shared key-value map can have data shared amongst the APIs
env.someSharedKeyValueMap['key'] = 'test'
return op.returnJson({ data: 'Hello World!' })
},
)