@routup/query
TypeScript icon, indicating that this package has built-in type declarations

2.4.1 • Public • Published

@routup/query

npm version main codecov Known Vulnerabilities Conventional Commits

This is a plugin for reading and parsing the query string of the request url.

Table of Contents

Installation

npm install @routup/query --save

Documentation

To read the docs, visit https://routup.net

Usage

It is important to invoke the request middleware, to parse the query-string of the request url.

import { createServer } from 'node:http';
import {
    createNodeDispatcher,
    coreHandler,
    Router
} from 'routup';
import {
    query,
    useRequestQuery
} from '@routup/query';

const router = new Router();

router.use(query());

router.get('/', coreHandler((req, res) => {
    const query = useRequestQuery(req);
    console.log(query);
    // { key: ..., ... }
}));

const server = createServer(createNodeDispatcher(router));
server.listen(3000);

Helpers

setRequestQuery

This function sets the parsed request query parameters for the current request.

declare function setRequestQuery(
    req: Request,
    key: string,
    value: unknown
) : void;

declare function setRequestQuery(
    req: Request, 
    record: Record<string, any>,
    append?: boolean
) : void;

useRequestQuery

This function returns the query parameters of the request.

declare function useRequestQuery(
    req: Request
) : Record<string, any>;

declare function useRequestQuery(
    req: Request, 
    key: string
) : any;

License

Made with 💚

Published under MIT License.

Package Sidebar

Install

npm i @routup/query

Weekly Downloads

137

Version

2.4.1

License

MIT

Unpacked Size

24.6 kB

Total Files

19

Last publish

Collaborators

  • tada5hi