Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vaneenige/unvault-middleware
📦 A middleware to automatically setup routes, store expected responses and deliver results fast.
https://github.com/vaneenige/unvault-middleware
api middleware node responses routing server store
Last synced: about 2 hours ago
JSON representation
📦 A middleware to automatically setup routes, store expected responses and deliver results fast.
- Host: GitHub
- URL: https://github.com/vaneenige/unvault-middleware
- Owner: vaneenige
- License: mit
- Created: 2018-01-25T20:44:58.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-27T16:51:10.000Z (almost 7 years ago)
- Last Synced: 2024-08-10T11:28:36.398Z (3 months ago)
- Topics: api, middleware, node, responses, routing, server, store
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Unvault Middleware
As the name suggests this is a middleware based on [unvault](https://github.com/vaneenige/unvault), a minimal layer for node that allows results of time-consuming tasks to be stored. This middleware only needs a simple configuration to automatically setup routes, store expected responses and deliver results fast (see [benchmarks](https://github.com/vaneenige/unvault#benchmarks)).
## Install
```
$ npm install --save unvault-middleware
```## Usage
```js
const polka = require("polka");
const middleware = require("unvault-middleware");const route = {
path: "/random",
headers: { "Content-Type": "application/json" },
interval: 1000,
update: () => {
return JSON.stringify({
random: Math.random()
});
}
};polka()
.use(middleware([route]))
.listen(3000);
```**Result:** The example above creates a node server (in this case with [Polka](https://github.com/lukeed/polka)) that uses the middleware. The added route (`http://localhost:3000/random`) will return a stored JSON (based on headers) response with a random value that is updated automatically every second.
## License
MIT © [Colin van Eenige](https://use-the-platform.com).