8000 GitHub - mapljs/body: Body parsers for Mapl
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

mapljs/body

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@mapl/body

Body parsers for @mapl/app.

JSON parser

JSON parser requires a stnl schema for validation.

import { json } from '@mapl/body';

app
  // Set the type for the request body
  .macro(json({
    props: {
      name: {
        type: 'string',
        minLength: 3,
        maxLength: 32
      },
      age: 'i8'
    }
  }))
  // Return the username with age from the request body
  .post('/name', (c) => `${c.body.name} - ${c.body.age}`);

Other parsers

These parsers don't require a schema for validation.

import { stream } from '@mapl/body';

// Parse body to ReadableStream
app.macro(stream);

Exception handling

Register a handler to be get executed when the body payload is invalid:

import { invalidBodyException } from '@mapl/body';

app.catch(invalidBodyException, (c) => {
  c.status = 400;
  return 'Invalid body payload';
});

About

Body parsers for Mapl

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0