1.3.2 • Published 2 months ago

@routup/basic v1.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

@routup/basic

npm version main codecov Known Vulnerabilities Conventional Commits

This is a bundle plugin which includes the following plugins:

  • body A plugin for reading and parsing the request payload.
  • cookie A plugin for reading and parsing request cookies, as well serializing cookies for the response.
  • query A plugin for reading and parsing the query string of the request url.

Table of Contents

Installation

npm install @routup/basic --save

Documentation

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

Usage

The modules body, cookie and query have an individual export path as shown in the following code snippet.

import { createServer } from 'node:http';
import {
    createNodeDispatcher,
    coreHandler,
    Router
} from 'routup';
import { basic } from '@routup/basic';
import { useRequestBody } from '@routup/basic/body';
import { useRequestCookie, useRequestCookies } from '@routup/basic/cookie';
import { useRequetQuery } from '@routup/basic/query';

const router = new Router();

router.use(basic());

router.get('/', coreHandler((req, res) => {
    const body = useRequestBody(req);
    // { key: value, ... }
    
    const cookies = useRequestCookies(req);
    // { key: value, ... }
    
    const cookie = useRequestCookie(req, 'key');
    // value
    
    const query = useRequetQuery(req);
    // query
}));

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

Options

body

Configure the body plugin.

  • Type: Options | boolean
  • Default: true

cookie

Configure the cookie plugin.

  • Type: Options | boolean
  • Default: true

query

Configure the query plugin.

  • Type: Options | boolean
  • Default: true

License

Made with 💚

Published under MIT License.