Body parsing
Install @mapl/body
and stnl
from npm.
bun i @mapl/body stnl
Then we register the body parser to the app instance and use the parsed body.
import { text as parseBodyAsText } from '@mapl/body';
const app = router() // This get inlined into the control flow .macro(parseBodyAsText) // Use the parse body in a route .post('/text', (c) => c.body);
To catch when the body is invalid:
import { invalidBodyException } from '@mapl/body';
app.catch(invalidBodyException, (c) => { c.status = 400; return 'Invalid body payload';});
You can see the list of available parsers here.