Skip to content
beta

Request

Harpia Core provides an enhanced Request class that extends Bun’s native Request, giving you everything you’re used to—plus a few extra tools that make backend development smoother.

To use it in your routes:

import { type Request } from "harpiats";

Auto-parsed route parameters based on your route definition:

router.get("/users/:id", (req, res) => {
const userId = req.params.id;
res.send(`User ID is ${userId}`);
});

Auto-parsed query strings as a key-value object:

// For a URL like /search?q=harpia&page=2
router.get("/search", (req, res) => {
const { q, page } = req.query;
res.send(`Searching for "${q}", page ${page}`);
});

Always returns the HTTP method in uppercase (e.g., "GET", "POST"):

router.get("/inspect", (req, res) => {
res.send(`Request method is ${req.method}`);
});

Simplified cookie management:

// Single cookie
const token = req.cookies.get("auth_token");
// All cookies
const allCookies = req.cookies.getAll();

More information about Cookies is available in the Cookies section.


Since Harpia’s Request class extends Bun’s native one, you still have access to all original methods:

Parses the request body as JSON.

const body = await req.json();

Parses the body as form data.

const form = await req.formData();
const file = form.get("avatar");

Access the full request URL:

const fullUrl = req.url;

Reads the body as plain text.

const text = await req.text();

Redirects to another URL.

return req.redirect("/login", 302);

Note: In most cases, you’ll want to use res.redirect() instead, which is part of Harpia’s response utilities.


To get full IntelliSense and type support, always annotate the request:

import { type Request, type Response } from "harpiats";
router.get("/profile", (req: Request, res: Response) => {
const cookies = req.cookies.getAll();
res.json({ cookies });
});