joyrouter
v1.1.1
Published
JoyRouter is a router designed for cloudflare workers.
Downloads
5
Readme
JoyRouter
JoyRouter is a router designed for cloudflare workers.
It has many functionalities, such as:
- Swagger UI documentation
- Automatic OPTIONS request handling
- Middleware
- JSON responses
- Error responses
- And more!
To access swagger ui, go to the url of your worker with the path '/docs'.
This page can be disabled by setting the internalRoutes
option to false.
It is highly recommended to use the jrdoc
tag along with Jrdoc Highlighting for VSCode.
This will ease the process of creating your routes.
Documentation
Documentation can be found here.
Installation
npm i joyrouter
Usage
import { JoyRouter } from "joyrouter";
const router = new JoyRouter();
function post_path(request: Request) {
return new Response("Hello world!", { status: 200 });
}
function get_path(request: Request, returnable: string) {
/*jrdoc*/`
An example function that returns the query parameter.
@param where:query type:string name:returnable | The parameter to return
`;
return new Response(returnable, { status: 200 });
}
router
.json("GET", "/", { detail: "Hello world!" }, 200)
.post("/", post_path);
.get
export default {
async fetch(request: Request) {
return await router.handle(req);
},
};