# overalls

> Decorate HTTP requests with path parameters

Latest version **1.0.4** (published 2015-04-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install overalls
pnpm add overalls
yarn add overalls
bun add overalls
```

## 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 | 1.0.4 |
| Published | 2015-04-04 |
| First published | 2015-04-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | William Fisher |
| Maintainers | filwisher |
| Keywords | path, parameters, route, http, router |

## Links

- npm: https://www.npmjs.com/package/overalls
- Repository: https://github.com/FilWisher/overalls
- Issues: https://github.com/FilWisher/overalls/issues
- npm.io page: https://npm.io/package/overalls

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.4 (latest) — 2015-04-04
- 1.0.3 — 2015-04-04
- 1.0.2 — 2015-04-04
- 1.0.1 — 2015-04-04
- 1.0.0 — 2015-04-02

## README

# overalls

[![Code Climate](https://codeclimate.com/github/FilWisher/overalls/badges/gpa.svg)](https://codeclimate.com/github/FilWisher/overalls) [![Test Coverage](https://codeclimate.com/github/FilWisher/overalls/badges/coverage.svg)](https://codeclimate.com/github/FilWisher/overalls)

A small routing tool to decorate HTTP requests with path parameters



##### use:
```js
var http = require("http");
var overalls = require("overalls");

// parameters are between {curlybraces}
var routes = ["GET /", "GET /dogs/{dog}", "GET /cats/{cat}"];

// overalls is configured with an array of keys
// (or object with paths as keys) i.e { "GET /": function (req, res) {...} }
var decorate = overalls(routes);

var server = http.createServer(function (req, res) {

  //decorate adds request parameters from the matching path to req.params
  decorate(req);

  res.writeHead(200, {"Content-Type": "text/plain"});

  if(req.params) {
    if (req.params.dog) {
      res.write("dogs: " + req.params.dog);
    } else if (req.params.cat) {
      res.write("cat: " + req.params.cat);
    }

  } else {
    res.write("no params");
  }
  res.end();

});

server.listen(4444);

console.log("listening on 4444");
```
(Also look at /examples for more examples)


## api

overalls exposes a single function:

### overalls(routes)

 ```routes``` - an array (or object) of paths.
 e.g:
 ```
 var routes = ["GET /", "GET /articles/{article}", "GET /issues/{issue}"];
 ```
 or
 ```
 var routes = {
   "GET /": function (req, res) {...},
   "GET /articles/{article}": function (req, res) {...}
 }
 ```

```returns``` - a decorate function with the signature:```decorate(req)```

### decorate(req)

```req``` - a HTTP request object (although this will work with any object with method and url properties.

Calling decorate on the request object will attempt to match the request path to a path from routes. If there is a matching path, ```req``` will be decorated with a ```params``` property.

The ```params``` property will contain the parameter names as keys.

For example, if decorate() matches the route ``` "GET /articles/{article}" ``` with a GET request to ```"/articles/13"```, the request object will look like this:
```
{
  path: "GET /articles/13",
  params: {
    article: "13"
  },
  ...
}
```

## license

MIT

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