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

@types/accepts

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/accepts

TypeScript definitions for accepts

  • 1.3.7
  • ts4.5
  • ts4.6
  • ts4.7
  • ts4.8
  • ts4.9
  • ts5.0
  • ts5.1
  • ts5.2
  • ts5.3
  • ts5.4
  • ts5.5
  • ts5.6
  • ts5.7
  • ts5.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.1M
decreased by-4.87%
Maintainers
1
Weekly downloads
 
Created

What is @types/accepts?

The @types/accepts npm package provides TypeScript type definitions for the 'accepts' npm package, which is a utility for content negotiation in HTTP requests. It allows developers to use TypeScript to ensure type safety when working with HTTP Accept headers for determining the preferred content types, encodings, charsets, and languages from HTTP requests.

What are @types/accepts's main functionalities?

Content Type Negotiation

This feature allows the server to negotiate and determine the most appropriate content type to respond with, based on the client's Accept header. The code sample demonstrates how to use the 'accepts' library to select between 'json' and 'html' formats.

import accepts from 'accepts';
import http from 'http';

http.createServer((req, res) => {
  const accept = accepts(req);
  const preferredType = accept.type(['json', 'html']);
  res.setHeader('Content-Type', preferredType);
  res.end(`Content type set to ${preferredType}`);
}).listen(3000);

Encoding Negotiation

This feature enables the server to select the best encoding method for the response based on the client's Accept-Encoding header. The code sample shows how to determine whether to use 'gzip' or 'deflate' encoding.

import accepts from 'accepts';
import http from 'http';

http.createServer((req, res) => {
  const accept = accepts(req);
  const preferredEncoding = accept.encoding(['gzip', 'deflate']);
  res.setHeader('Content-Encoding', preferredEncoding);
  res.end(`Content encoding set to ${preferredEncoding}`);
}).listen(3000);

Language Negotiation

This feature helps in determining the preferred language for the response content based on the client's Accept-Language header. The code sample illustrates how to choose between English ('en') and Spanish ('es').

import accepts from 'accepts';
import http from 'http';

http.createServer((req, res) => {
  const accept = accepts(req);
  const preferredLanguage = accept.language(['en', 'es']);
  res.setHeader('Content-Language', preferredLanguage);
  res.end(`Content language set to ${preferredLanguage}`);
}).listen(3000);

Other packages similar to @types/accepts

FAQs

Package last updated on 06 Nov 2023

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