ictx (Invocation Context)
Globally maintains context throughout a invocation/request lifecycle, using cls-hooked under the hood.
Context can be set and retrieved during the entire lifetime a request, through all chains of function calls, even if defined in another module entirely.
Examples
Context.Middlware (for Express)
;; ; app.useContext.Middleware; app.get'/me', ;
Certain headers will be automatically assigned as context properties:
x-user-id
can be accessed viaContext.get('userId')
orContext.userId()
x-invocation-id
/x-request-id
can be accessed viaContext.get('invocationId')
orContext.invocationId()
Context.Provider
Generic provider. Works much like Context.Middlware
, except you don't need to pass req
and res
.
; Context.Provider,;
Typed Context
;; ; Context.Provider;