# hapi-routes-prefixer

> A simple Hapi plugin for prefixing routes

Latest version **3.0.0** (published 2017-03-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install hapi-routes-prefixer
pnpm add hapi-routes-prefixer
yarn add hapi-routes-prefixer
bun add hapi-routes-prefixer
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2017-03-25 |
| First published | 2017-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | dipesh |
| Maintainers | dipesh.singh |
| Keywords | hapi, hapi.js, node, node.js, routes, plugin, route-prefix |

## Links

- npm: https://www.npmjs.com/package/hapi-routes-prefixer
- Repository: https://github.com/10uei011/hapi-routes-prefixer
- Homepage: https://github.com/10uei011/hapi-routes-prefixer#readme
- Issues: https://github.com/10uei011/hapi-routes-prefixer/issues
- npm.io page: https://npm.io/package/hapi-routes-prefixer

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2017-03-25
- 2.0.0 — 2017-03-21
- 1.0.0 — 2017-03-21

## README

# hapi-routes-prefixer

A simple plugin to prefix routes with strings such as '/v1' or '/api'.

## Why?

When we want to apply prefix 	to individual route plugins but not to all of the
plugins registered with the server object.

## Installation

```bash
npm install --save hapi-routes-prefixer 
```

## Usage

After installing register the module as a plugin.

```js
var Hapi = require('hapi');
var server = new Hapi.Server();
var prefixer = require('hapi-routes-prefixer');

server.connection({
	port: 3000,
	host: localhost
});

server.register([
	{
		register: prefixer
	},
	{
		register: 'other plugins'
	}, function (err) {
		if (err) console.log('Failed to load plugins ',err);
		console.log('Server running at:', server.info.uri);
	}
]);
```



After registering the plugin, use it in your routes like this.

```js
exports.register = function (server, option, next) {

  var route = server.routePrefix('/api');

  route([
    {
      method: 'GET',
      path: '/users/{id}',
      handler: function (request, reply) {
      }
    },
    {
      method: 'POST',
      path: '/users',
      handler: function (request, reply) {
      	reply('created user');
      }
    },
  ]);

  next();
};

exports.register.attributes = {
  name: 'api.user',
  version: '1.0.0'
};
```
The above routes can be accessed at 'domain.com/api/users' now.

---
_Source: https://npm.io/package/hapi-routes-prefixer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
