@planigale/body-parser@0.2.0Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
raaymax/planigaleMiddleware for @planigale/planigale for body parsing
This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers
JSR Score
64%
Published
2 months ago (0.2.0)
import { Middleware } from 'jsr:@planigale/planigale@^0.6.1'; import { qs } from './deps.ts'; export const bodyParser: Middleware = async (req, next) => { const request = req.request; if (!req.route) { return await next(); } req.body = await loadBody(request); return await next(); }; const methods = ['POST', 'PUT', 'PATCH', 'DELETE']; const loadBody = async (request: Request) => { if (!methods.includes(request.method)) { return request.body; } const contentType = request.headers.get('content-type'); if (contentType?.includes('application/json')) { return await request.json(); } else if (contentType?.includes('application/x-www-form-urlencoded')) { return qs.parse(await request.text()); } else if (contentType?.includes('text/plain')) { return await request.text(); } else { return request.body; } };