🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@fastify/formbody

Package Overview
Dependencies
Maintainers
19
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/formbody

A module for Fastify to parse x-www-form-urlencoded bodies

8.0.2
latest
Source
npm
Version published
Weekly downloads
462K
-18.88%
Maintainers
19
Weekly downloads
 
Created

What is @fastify/formbody?

@fastify/formbody is a Fastify plugin that parses x-www-form-urlencoded bodies. It is useful for handling form submissions in Fastify applications.

What are @fastify/formbody's main functionalities?

Basic Form Body Parsing

This feature allows you to parse form data sent with the 'application/x-www-form-urlencoded' content type. The parsed data is available in the `request.body` object.

const fastify = require('fastify')();
const formbody = require('@fastify/formbody');

fastify.register(formbody);

fastify.post('/submit', (request, reply) => {
  const { name, age } = request.body;
  reply.send({ name, age });
});

fastify.listen(3000, err => {
  if (err) throw err;
  console.log('Server listening on http://localhost:3000');
});

Custom Body Limit

This feature allows you to set a custom limit for the size of the body that can be parsed. In this example, the limit is set to 1 MB.

const fastify = require('fastify')();
const formbody = require('@fastify/formbody');

fastify.register(formbody, { bodyLimit: 1048576 }); // 1 MB limit

fastify.post('/submit', (request, reply) => {
  const { name, age } = request.body;
  reply.send({ name, age });
});

fastify.listen(3000, err => {
  if (err) throw err;
  console.log('Server listening on http://localhost:3000');
});

Handling Nested Objects

This feature allows you to handle nested objects in form data. The nested objects are automatically parsed and available in the `request.body` object.

const fastify = require('fastify')();
const formbody = require('@fastify/formbody');

fastify.register(formbody);

fastify.post('/submit', (request, reply) => {
  const { user } = request.body; // user is an object with nested properties
  reply.send(user);
});

fastify.listen(3000, err => {
  if (err) throw err;
  console.log('Server listening on http://localhost:3000');
});

Other packages similar to @fastify/formbody

Keywords

fastify

FAQs

Package last updated on 10 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts