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

@fastify/cookie

Package Overview
Dependencies
Maintainers
19
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/cookie

Plugin for fastify to add support for cookies

  • 7.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
283K
decreased by-0.21%
Maintainers
19
Weekly downloads
 
Created

What is @fastify/cookie?

@fastify/cookie is a Fastify plugin that provides cookie parsing and serialization capabilities. It allows you to easily handle cookies in your Fastify applications, including setting, getting, and deleting cookies.

What are @fastify/cookie's main functionalities?

Setting a Cookie

This feature allows you to set a cookie in the client's browser. The code sample demonstrates how to set a cookie with various options such as domain, path, secure, httpOnly, and sameSite.

const fastify = require('fastify')();
const fastifyCookie = require('@fastify/cookie');

fastify.register(fastifyCookie);

fastify.get('/set-cookie', (request, reply) => {
  reply
    .setCookie('myCookie', 'cookieValue', {
      domain: 'example.com',
      path: '/',
      secure: true,
      httpOnly: true,
      sameSite: 'Strict'
    })
    .send({ hello: 'world' });
});

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

Getting a Cookie

This feature allows you to retrieve a cookie from the client's request. The code sample demonstrates how to access a cookie named 'myCookie' from the request object.

const fastify = require('fastify')();
const fastifyCookie = require('@fastify/cookie');

fastify.register(fastifyCookie);

fastify.get('/get-cookie', (request, reply) => {
  const myCookie = request.cookies.myCookie;
  reply.send({ myCookie });
});

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

Deleting a Cookie

This feature allows you to delete a cookie from the client's browser. The code sample demonstrates how to clear a cookie named 'myCookie' with a specified path.

const fastify = require('fastify')();
const fastifyCookie = require('@fastify/cookie');

fastify.register(fastifyCookie);

fastify.get('/delete-cookie', (request, reply) => {
  reply
    .clearCookie('myCookie', { path: '/' })
    .send({ hello: 'world' });
});

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

Other packages similar to @fastify/cookie

Keywords

FAQs

Package last updated on 15 Jul 2022

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