# path-proxy

> A path proxy object constructor

Latest version **1.0.0** (published 2014-01-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install path-proxy
pnpm add path-proxy
yarn add path-proxy
bun add path-proxy
```

## 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.0 |
| Published | 2014-01-09 |
| First published | 2013-12-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Jonathan Clem |
| Maintainers | jclem |
| Keywords | node, proxy |

## Links

- npm: https://www.npmjs.com/package/path-proxy
- Repository: https://github.com/jclem/path-proxy
- Issues: https://github.com/jclem/path-proxy/issues
- npm.io page: https://npm.io/package/path-proxy

## Dependencies (1)

- [inflection](https://npm.io/package/inflection.md) ~1.3.0

## 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

- 1.0.0 (latest) — 2014-01-09
- 0.1.1 — 2013-12-13
- 0.1.0 — 2013-12-12
- 0.0.0 — 2013-12-12

## README

# path-proxy

Given an group of paths (say, from an API schema), you might need to create a
set of proxy objects for interacting with those paths. This is the situation I
found myself in while working on the [Node client for the Heroku API][heroku_client].

Given a set of paths and a base constructor function, path-proxy will create a
network of logical proxy objects based on the paths and attach it to the
constructor's prototype.

## Install

```sh
npm install path-proxy --save
```

## Usage

```javascript
var pathProxy = require('path-proxy');

function ApiClient() {}

pathProxy.proxy(ApiClient, [
  "/foo",
  "/foo/{id}/bar"
]);

var client = new ApiClient();
client.foo("qux").bar();
```

This may not appear all that useful—they're mostly just empty functions—until you
start mucking around with their prototypes:

```javascript
var BarProxy = pathProxy.pathProxy(ApiClient, "/foo/{id}/bar");
BarProxy.prototype.sayHello = function () {
  console.log("hello");
};

client.foo("qux").bar().sayHello(); // Logs "hello".
```

They also have access to a few useful attributes:

```javascript
var baz = client.foo("qux").bar("baz");
baz.params;       // ["qux", "baz"]
baz.pathSegments; // ["foo", "qux", "bar", "baz"]
baz.path;         // "/foo/qux/bar/baz"
```

And can access the instance of the base constructor they're based off of:

```javascript
ApiClient.prototype.delete = function (path, callback) {
  var message = this.name + " deleted at " + path;
  callback(message);
};

var client = new ApiClient();
client.name = "Jonathan";

BarProxy.prototype.delete = function (callback) {
  this.base.delete(this.path, callback);
};

// This:
client.foo("qux").bar("baz").delete(function (message) {
  // message == "Jonathan deleted at /foo/qux/bar/baz"
});

// Is equivalent to this:
client.delete("/foo/qux/bar/baz", function (message) {
  // message == "Jonathan deleted at /foo/qux/bar/baz"
});
```

## Tests

path-proxy uses jasmine-node for tests. To run them:

```sh
$ npm install
$ npm test
```

[heroku_client]: https://github.com/heroku/node-heroku-client

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