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

fastify-url

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-url

Fastify plugin for parsing and attaching URL data to requests

  • 0.2.3
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

fastify-url

NPM Build Status codecov.io Code Coverage Greenkeeper badge

A plugin for fastify for accessing an incoming request's URL data.

fastify-url is inspired by fastify-url-data and is just a thin wrapper around Node's URL object.

Usage

const fastify = require('fastify')();

fastify.register(require('fastify-url').default);

fastify.get('/*', (req, reply) => {
  const url = req.url();

  req.log.info(url.host);          // 'sub.example.com:8080'
  req.log.info(url.hostname);      // 'sub.example.com'
  req.log.info(url.href);          // 'http://user:pass@sub.example.com:8080/p/a/t/h?query=string'
  req.log.info(url.origin);        // 'http://sub.example.com:8080'
  req.log.info(url.password);      // 'pass'
  req.log.info(url.pathname);      // '/p/a/t/h'
  req.log.info(url.port);          // '8080'
  req.log.info(url.protocol);      // 'http:'
  req.log.info(url.search);        // '?query=string'
  req.log.info(url.username);      // 'user'

  // if you just need single data:
  req.log.info(req.url('pathname')); // '/p/a/t/h'

  reply.send();
});

// GET: 'http://user:pass@sub.example.com:8080/p/a/t/h?query=string'

Options

protocol

Type: string Default: http

This property allows you to change the protocol the incoming request's URL object will absorb. This is used because it's difficult to find the protocol the request was received from within the request handler.

fastify-url vs fastify-url-data

The difference between these two plugins is fastify-url uses the native NodeJS URL class and fastify-url-data uses uri-js. These implementations provide some of the same features but have different data members. Depending on your requirements you may need one or the other, but using both is redundant.

Keywords

FAQs

Package last updated on 02 Sep 2019

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