Wayne is an open source service worker routing library designed to simplify and enhance in-browser HTTP requests. By utilizing service workers, it allows developers to efficiently manage network interactions, improving performance and user experience while providing a flexible approach to route handling.
Wayne is an open-source service worker routing library designed to facilitate in-browser HTTP requests. With a simple API structured akin to Express, Wayne empowers developers to create innovative web applications that can handle HTTP requests efficiently within the context of a service worker.
Define routes with ease, such as:
const users = {
1: 'Jakub T. Jankiewicz',
2: 'John Doe',
3: 'Jane Doe'
};
app.get('/user/{id}', function(req, res) {
const user = users[req.params.id];
if (user) {
res.json({result: user});
} else {
res.json({error: 'User Not Found'});
}
});
Easily access a virtual file system to handle file operations:
import { Wayne, FileSystem } from 'https://cdn.jsdelivr.net/npm/@jcubic/wayne';
import FS from "https://cdn.skypack.dev/@isomorphic-git/lightning-fs";
import mime from "https://cdn.skypack.dev/mime";
const { promises: fs } = new FS("__wayne__");
const app = new Wayne();
app.use(FileSystem({ path, fs, mime, prefix: '__fs__' }));
Stream updates to the client effortlessly:
app.get('/sse', function(req, res) {
const stream = res.sse();
const timerId = setInterval(function() {
stream.send({ data: (new Date()).toString() });
}, 1000);
});
Wayne supports various advanced functionalities, such as filtering requests based on origin, caching responses, and performing remote procedure calls (RPC). This flexibility accommodates sophisticated application needs, ensuring that developers can build robust web applications efficiently.
By using Wayne, developers can leverage the capabilities of service workers for routing HTTP requests locally. This approach not only enhances application resilience and performance but also promotes engaging user experiences, especially under offline conditions. For more detailed examples and a live demo, visit the project’s documentation.
No comments yet.
Sign in to be the first to comment.