Skip to main content
As an Apophis SDK consumer, you will likely only ever need to call Apophis.use(...middlewares) to register the middlewares you are interested in:
Duplicate middlewares are de-duped by instance, so you can “nest” middlewares to bundle dependencies. The DefaultCosmWasmMiddlewares, for example, depend on the DefaultCosmosMiddlewares, so you really only need to register ...DefaultCosmosMiddlewares, but it won’t hurt to also register ...DefaultCosmWasmMiddlewares.

Implementing Middleware

Middlewares are arbitrary multi-level objects that are registered in a global array and executed by some strategy defined at the callsite. If a middleware does not implement a method, it is automatically skipped. The following examples are valid middlewares:

Pipelines

Callsites of middlewares must specify the strategy by which to execute the middleware stack. There are various strategies implemented by the internal MiddlewarePipeline class, which adheres to the following interface:
KP is the key path to the middleware and serves to extract the correct function signature. Following is an example of how to use the mw function which produces such a MiddlewarePipeline:

Middleware Stack

The mw method exposes some additional properties. One of these properties is mw.stack which is an array of all registered middlewares. If necessary, you can inspect or even alter the stack: