{"bugs":{"url":"https://github.com/jclem/path-proxy/issues"},"dist":{"shasum":"2d2a1646865859128937e35bb4fcc704fc09d1cd","tarball":"https://registry.npmjs.org/path-proxy/-/path-proxy-0.1.0.tgz","integrity":"sha512-vSEDL+m8+/zGDnXRmGEF9pKRPZjownH+4wGygy7cH6HRlNgrOQZHRG9f3+M1DF9SAXUdI+V+1mHVGl3RlEN3eg==","signatures":[{"sig":"MEUCIQDrnM7er4ngtKbnX1E9/KQ+cW16dAPDkuYXp4dgGiEaHwIgRSwJB6lZSdP3trxcWJQW4rlBMq+v1MRj+ioyFl5dGJ4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","name":"path-proxy","_from":".","author":{"name":"Jonathan Clem"},"readme":"# path-proxy\n\nGiven an group of paths (say, from an API schema), you might need to create a\nset of proxy objects for interacting with those paths. This is the situation I\nfound myself in while working on the [Node client for the Heroku API][heroku_client].\n\nGiven a set of paths and a base constructor function, path-proxy will create a\nnetwork of logical proxy objects based on the paths and attach it to the\nconstructor's prototype.\n\n## Install\n\n```sh\nnpm install path-proxy --save\n```\n\n## Usage\n\n```javascript\nvar pathProxy = require('path-proxy');\n\nfunction ApiClient() {}\n\npathProxy.proxy(ApiClient, [\n  \"/foo\",\n  \"/foo/{id}/bar\"\n]);\n\nvar client = new ApiClient();\nclient.foo(\"qux\").bar();\n```\n\nThis may not appear all that useful—they're mostly just empty functions—until you\nstart mucking around with their prototypes:\n\n```javascript\nvar BarProxy = pathProxy.pathProxy(ApiClient, \"/foo/{id}/bar\");\nBarProxy.prototype.sayHello = function () {\n  console.log(\"hello\");\n};\n\nclient.foo(\"qux\").bar().sayHello(); // Logs \"hello\".\n```\n\nThey also have access to a few useful attributes:\n\n```javascript\nvar baz = client.foo(\"qux\").bar(\"baz\");\nbaz.params;       // [\"qux\", \"baz\"]\nbaz.pathSegments; // [\"foo\", \"qux\", \"bar\", \"baz\"]\nbaz.path;         // \"/foo/qux/bar/baz\"\n```\n\nAnd can access the instance of the base constructor they're based off of:\n\n```javascript\nApiClient.prototype.delete = function (path, callback) {\n  var message = this.name + \" deleted at \" + path;\n  callback(message);\n};\n\nvar client = new ApiClient();\nclient.name = \"Jonathan\";\n\nBarProxy.prototype.delete = function (callback) {\n  this.base.delete(this.path, callback);\n};\n\n// This:\nclient.foo(\"qux\").bar(\"baz\").delete(function (message) {\n  // message == \"Jonathan deleted at /foo/qux/bar/baz\"\n});\n\n// Is equivalent to this:\nclient.delete(\"/foo/qux/bar/baz\", function (message) {\n  // message == \"Jonathan deleted at /foo/qux/bar/baz\"\n});\n```\n\n## The End\n\nThat's all there is for now. This is might prove to be a useful tool for working\non documented API clients in the future. For now, don't rely on it. There are\nno tests, and it's more of a fun experiment at the moment\n\n[heroku_client]: https://github.com/heroku/node-heroku-client\n","license":"MIT","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"jclem","email":"jonathan@jclem.net"},"keywords":["node","proxy"],"repository":{"url":"https://github.com/jclem/path-proxy","type":"git"},"_npmVersion":"1.3.11","description":"A path proxy object constructor","directories":{},"maintainers":[{"name":"jclem","email":"jonathan@jclem.net"}],"dependencies":{"inflection":"~1.3.0"},"readmeFilename":"README.md","_id":"path-proxy@0.1.0","version":"0.1.0"}