Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fastify/fastify-url-data
A plugin to provide access to the raw URL components
https://github.com/fastify/fastify-url-data
fastify fastify-plugin
Last synced: 4 days ago
JSON representation
A plugin to provide access to the raw URL components
- Host: GitHub
- URL: https://github.com/fastify/fastify-url-data
- Owner: fastify
- License: mit
- Created: 2017-10-30T13:52:04.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2025-01-07T18:53:32.000Z (18 days ago)
- Last Synced: 2025-01-15T02:08:40.652Z (11 days ago)
- Topics: fastify, fastify-plugin
- Language: JavaScript
- Homepage: https://npmjs.com/package/@fastify/url-data
- Size: 144 KB
- Stars: 57
- Watchers: 17
- Forks: 16
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-fastify - `fastify-url-data`
README
# @fastify/url-data
[![CI](https://github.com/fastify/fastify-url-data/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-url-data/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/url-data.svg?style=flat)](https://www.npmjs.com/package/@fastify/url-data)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)A plugin for [Fastify](https://fastify.dev/) that adds support for getting raw
URL information from the request.## Install
```
npm i @fastify/url-data
```### Compatibility
| Plugin version | Fastify version |
| ---------------|-----------------|
| `^6.x` | `^5.x` |
| `^5.x` | `^4.x` |
| `^3.x` | `^3.x` |
| `^2.x` | `^2.x` |
| `^2.x` | `^1.x` |Please note that if a Fastify version is out of support, then so are the corresponding versions of this plugin
in the table above.
See [Fastify's LTS policy](https://github.com/fastify/fastify/blob/main/docs/Reference/LTS.md) for more details.## Example
```js
const fastify = require('fastify')()fastify.register(require('@fastify/url-data'))
fastify.get('/foo', (req, reply) => {
const urlData = req.urlData()
req.log.info(urlData.path) // '/foo'
req.log.info(urlData.query) // 'a=b&c=d'
req.log.info(urlData.host) // '127.0.0.1'
req.log.info(urlData.port) // 8080// if you just need single data:
req.log.info(req.urlData('path')) // '/foo'reply.send({hello: 'world'})
})// GET: 'http://127.0.0.1:8080/foo?a=b&c=d
```## License
Licensed under [MIT](./LICENSE).