Skip to main content
Deno 2 is finally here 🎉️
Learn more

rp1

Blazingly fast and simple web framework for Deno, suitably named after the rocket fuel.

import Router from "https://deno.land/x/rp1/mod.ts";

const router = new Router();

router.get("/", () => "Hello World!");

Deno.serve(router.handle);

Features

Generates JSON if you return an object.

// '{ "data": [1, 2, 3] }' with a 200 status code
router.get("/json", () => { data: [1, 2, 3] });

Sane error handling.

import { ServerError } from "https://deno.land/x/rp1/mod.ts";

// '{ "error": { "status": 402, "message": "Expected dollars!" } }'
router.post("/paypal", () => {
    throw new ServerError({
        status: 402,
        message: "Expected dollars!"
    });
});

You can return Response objects.

// 'Hello World!'
router.get("/hello", () => new Response("Hello World!"));

Easy to use middleware.

// Simple request logger
router.use(async ({ request }, next) => {
    const method = request.method;
    const url = new URL(request.url);
    const path = url.pathname;

    console.log(`${method} ${path}`);

    await next();
});

CORS middleware included.

import { cors } from "https://deno.land/x/rp1/mod.ts";

router.use(cors());

Configure CORS easily.

import { cors, echo } from "https://deno.land/x/rp1/mod.ts";

router.use(cors({
    origin: echo,
    methods: ["GET", "POST"],
    headers: ["Content-Type"],
}));

Uses native Request object, so WebSockets are supported.

router.get("/ws", ({ request }) => {
    const { socket, response } = Deno.upgradeWebSocket(request);
    
    socket.onopen = () => {
        console.log("Socket opened!");
    };

    // ...

    return response;
});