@aws-sdk/middleware-stack
Provides a means for composing multiple middleware functions into a single handler
Last updated 4 years ago by aws-sdk-bot .
Apache-2.0 · Original npm · Tarball · package.json
$ npm install @aws-sdk/middleware-stack 
SYNC missed versions from official npm registry.

@aws-sdk/middleware-stack

NPM version NPM downloads

The package contains an implementation of middleware stack interface. Middleware stack is a structure storing middleware in specified order and resolve these middleware into a single handler.

A middleware stack has five Steps, each of them represents a specific request life cycle:

  • initialize: The input is being prepared. Examples of typical initialization tasks include injecting default options computing derived parameters.

  • serialize: The input is complete and ready to be serialized. Examples of typical serialization tasks include input validation and building an HTTP request from user input.

  • build: The input has been serialized into an HTTP request, but that request may require further modification. Any request alterations will be applied to all retries. Examples of typical build tasks include injecting HTTP headers that describe a stable aspect of the request, such as Content-Length or a body checksum.

  • finalizeRequest: The request is being prepared to be sent over the wire. The request in this stage should already be semantically complete and should therefore only be altered to match the recipient's expectations. Examples of typical finalization tasks include request signing and injecting hop-by-hop headers.

  • deserialize: The response has arrived, the middleware here will deserialize the raw response object to structured response

Adding Middleware

There are two ways to add middleware to a middleware stack. They both add middleware to specified Step but they provide fine-grained location control differently.

Absolute Location

You can add middleware to specified step with:

stack.add(middleware, {
  step: "finalizeRequest",
});

This approach works for most cases. Sometimes you want your middleware to be executed in the front of the Step, you can set the Priority to high. Set the Priority to low then this middleware will be executed at the end of Step:

stack.add(middleware, {
  step: "finalizeRequest",
  priority: "high",
});

If multiple middleware is added to same step with same priority, the order of them is determined by the order of adding them.

Relative Location

In some cases, you might want to execute your middleware before some other known middleware, then you can use addRelativeTo():

stack.add(middleware, {
  step: "finalizeRequest",
  name: "myMiddleware",
});
stack.addRelativeTo(anotherMiddleware, {
  step: "finalizeRequest",
  relation: "before", //or 'after'
  toMiddleware: "myMiddleware",
});

You need to specify the step in addRelativeTo(). This is because the middleware function signature of each step is different, middleware for different step should not be mixed. The previous middleware must have a unique name, this is the only way to refer a known middleware when adding middleware relatively. Note that if specified step doesn't have a middleware named as the value in toMiddleware, this middleware will fallback to be added with absolute location.

You can do this:

stack.addRelativeTo(middleware1, {
  step: "finalizeRequest",
  name: "Middleware1",
  relation: 'before',
  toMiddleware: 'middleware2'
}); //this will fall back to `add()`
stack.addRelativeTo(middleware2, {
  step: "finalizeRequest",
  name: 'Middleware2'
  relation: "after",
  toMiddleware: "Middleware1"
}); //this will be added after middleware1

Removing Middleware

You can remove middleware by name one at a time:

stack.remove("Middleware1");

If you specify tags for middleware, you can remove multiple middleware at a time according to tag:

stack.add(middleware, {
  step: "finalizeRequest",
  tags: ["final"],
});
stack.removeByTag("final");

Current Tags

  • 1.0.0-alpha.6                                ...           alpha (5 years ago)
  • 1.0.0-beta.4                                ...           beta (5 years ago)
  • 1.0.0-gamma.8                                ...           gamma (4 years ago)
  • 3.374.0                                ...           latest (a year ago)
  • 0.1.0-preview.9                                ...           preview (5 years ago)
  • 1.0.0-rc.10                                ...           rc (4 years ago)

120 Versions

  • 3.374.0 [deprecated]           ...           a year ago
  • 3.370.0                                ...           a year ago
  • 3.369.0                                ...           a year ago
  • 3.357.0                                ...           2 years ago
  • 3.347.0                                ...           2 years ago
  • 3.342.0                                ...           2 years ago
  • 3.341.0                                ...           2 years ago
  • 3.338.0                                ...           2 years ago
  • 3.337.0                                ...           2 years ago
  • 3.329.0                                ...           2 years ago
  • 3.325.0                                ...           2 years ago
  • 3.310.0                                ...           2 years ago
  • 3.306.0                                ...           2 years ago
  • 3.303.0                                ...           2 years ago
  • 3.296.0                                ...           2 years ago
  • 3.295.0                                ...           2 years ago
  • 3.292.0                                ...           2 years ago
  • 3.290.0                                ...           2 years ago
  • 3.289.0                                ...           2 years ago
  • 3.272.0                                ...           2 years ago
  • 3.271.0                                ...           2 years ago
  • 3.267.0                                ...           2 years ago
  • 3.266.1                                ...           2 years ago
  • 3.266.0                                ...           2 years ago
  • 3.257.0                                ...           2 years ago
  • 3.254.0                                ...           2 years ago
  • 3.226.0                                ...           2 years ago
  • 3.224.0                                ...           2 years ago
  • 3.222.0                                ...           2 years ago
  • 3.215.0                                ...           2 years ago
  • 3.212.0                                ...           2 years ago
  • 3.208.0                                ...           2 years ago
  • 3.201.0                                ...           2 years ago
  • 3.200.0                                ...           2 years ago
  • 3.198.0                                ...           2 years ago
  • 3.197.0                                ...           2 years ago
  • 3.193.0                                ...           2 years ago
  • 3.190.0                                ...           2 years ago
  • 3.188.0                                ...           2 years ago
  • 3.186.0                                ...           2 years ago
  • 3.183.0                                ...           2 years ago
  • 3.178.0                                ...           2 years ago
  • 3.171.0                                ...           2 years ago
  • 3.170.0                                ...           2 years ago
  • 3.168.0                                ...           2 years ago
  • 3.162.0                                ...           2 years ago
  • 3.160.0                                ...           2 years ago
  • 3.159.0                                ...           2 years ago
  • 3.127.0                                ...           2 years ago
  • 3.110.0                                ...           3 years ago
  • 3.109.0                                ...           3 years ago
  • 3.78.0                                ...           3 years ago
  • 3.55.0                                ...           3 years ago
  • 3.54.1                                ...           3 years ago
  • 3.54.0                                ...           3 years ago
  • 3.53.0                                ...           3 years ago
  • 3.52.0                                ...           3 years ago
  • 3.50.0                                ...           3 years ago
  • 3.49.0                                ...           3 years ago
  • 3.47.2                                ...           3 years ago
  • 3.47.1                                ...           3 years ago
  • 3.47.0                                ...           3 years ago
  • 3.46.0                                ...           3 years ago
  • 3.40.0                                ...           3 years ago
  • 3.38.0                                ...           3 years ago
  • 3.37.0                                ...           3 years ago
  • 3.36.0                                ...           3 years ago
  • 3.35.0                                ...           3 years ago
  • 3.34.0                                ...           3 years ago
  • 3.32.0                                ...           3 years ago
  • 3.29.0                                ...           3 years ago
  • 3.25.0                                ...           3 years ago
  • 3.23.0                                ...           3 years ago
  • 3.22.0                                ...           3 years ago
  • 3.20.0                                ...           3 years ago
  • 3.18.0                                ...           4 years ago
  • 3.15.0                                ...           4 years ago
  • 3.13.1                                ...           4 years ago
  • 3.12.0                                ...           4 years ago
  • 3.10.0                                ...           4 years ago
  • 3.6.1                                ...           4 years ago
  • 3.4.1                                ...           4 years ago
  • 3.4.0                                ...           4 years ago
  • 3.1.0                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 1.0.0-rc.10                                ...           4 years ago
  • 1.0.0-rc.8                                ...           4 years ago
  • 1.0.0-rc.7                                ...           4 years ago
  • 1.0.0-rc.5                                ...           4 years ago
  • 1.0.0-rc.4                                ...           4 years ago
  • 1.0.0-rc.3                                ...           4 years ago
  • 1.0.0-rc.2                                ...           4 years ago
  • 1.0.0-rc.1                                ...           4 years ago
  • 1.0.0-gamma.8                                ...           4 years ago
  • 1.0.0-gamma.7                                ...           4 years ago
  • 1.0.0-gamma.6                                ...           4 years ago
  • 1.0.0-gamma.5                                ...           4 years ago
  • 1.0.0-gamma.4                                ...           4 years ago
  • 1.0.0-gamma.3                                ...           4 years ago
  • 1.0.0-gamma.2                                ...           4 years ago
  • 1.0.0-gamma.1                                ...           5 years ago
  • 1.0.0-beta.4                                ...           5 years ago
  • 1.0.0-beta.3                                ...           5 years ago
  • 1.0.0-beta.2                                ...           5 years ago
  • 1.0.0-beta.1                                ...           5 years ago
  • 1.0.0-alpha.6                                ...           5 years ago
  • 1.0.0-alpha.5                                ...           5 years ago
  • 1.0.0-alpha.4                                ...           5 years ago
  • 1.0.0-alpha.3                                ...           5 years ago
  • 1.0.0-alpha.2                                ...           5 years ago
  • 1.0.0-alpha.1                                ...           5 years ago
  • 0.1.0-preview.9                                ...           5 years ago
  • 0.1.0-preview.8                                ...           5 years ago
  • 0.1.0-preview.7                                ...           5 years ago
  • 0.1.0-preview.6                                ...           5 years ago
  • 0.1.0-preview.5                                ...           5 years ago
  • 0.1.0-preview.4                                ...           6 years ago
  • 0.1.0-preview.3                                ...           6 years ago
  • 0.1.0-preview.2                                ...           6 years ago
  • 0.1.0-preview.1                                ...           6 years ago
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (3)

© 2010 - cnpmjs.org x YWFE | Home | YWFE