This is a plugin for reading and parsing the query string of the request url.
Table of Contents
npm install @routup/query --save
To read the docs, visit https://routup.net
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);
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;
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;
Made with 💚
Published under MIT License.