Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fastify/formbody

Package Overview
Dependencies
Maintainers
0
Versions
13
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.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
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

FAQs

Package last updated on 22 Sep 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc