{"bugs":{"url":"https://github.com/silas/node-papi/issues"},"dist":{"shasum":"e409ce4b0a814a15fa9c6837558c36fb68f070fd","tarball":"https://registry.npmjs.org/papi/-/papi-1.0.0-alpha.2.tgz","fileCount":11,"integrity":"sha512-8GL1pvd0insoTZbDYLqlnBbNF9voXX86FK4qfrJCePOqIuN9zNOFCCR8e7okBG7kCvAZcEkzpUNMlR/REBXFwg==","signatures":[{"sig":"MEYCIQDFK/Q/r28VWX/TaeLn6/LnRexMWsG+wIEo2UxzeJJxugIhAIQjx5DhJ5jCaKS6w6L9NQXZt9WqDxqonMIrWMHvxlhZ","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":33684,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgK+t6CRA9TVsSAnZWagAAXM8P/2fPalTi9VPBBoiCdD9t\ndjh18jta8COsmfDOSgAEyGP4QmOYageXMBZD9eXavgOJW5CVxlbJbPhXsAaA\nGeWhY8TiKoRY43p396xgrsFa2szy382JBeo7n0mOZLy0IABpV3t6o6Xj+gUi\nkyJ1zlXDa8sqVuJD23ep1bOeqcL4mnxN3e+L+EwL39UcBwoMQP02HnhX6Nzj\nHsOhRgclTqjl/6/ihowz3Uj/6WJt8Z3mCeVfGZVKUQqCKqlKq5zgeG68B0jH\n/hthscyxnfgtlZTIb4aLixPNzBaDlOhZ5AmWXn2Ydv3vCxQ02Wo/2yYbLvBy\nnWv0fho9NWK0vh+6s2Ouq1CrT5JvXqDpVGQtK8G2kz5V5FtjJEcFePRQNkWc\nmTsHd839i0S09kN4jCko4uW6M1I9NiQrX5/Gppf/AU5S7sY3ATeSfkOLRlgE\nw+YZSCIKwdEDx1avnu1D6ICDmR+dKKa4zeEMz+cLrI2r1sidz0rXnaQFjGBv\nhCVDFMnvilgjKSPpP/9BSIepvBtiH1aFloUUXPImnex/yKYKhPLJwiE3xQ8P\nvWSZ6oXCGHHeU23OdaNuQ6cvJsbvj2bPUfYMsbp4D8BSflytBEd+/YWquUjf\nBZ7shXh7Bxw3kYtEG8yls9EtcVkqbVM0zKATncCrMFk+lwfU+q7K91Cm8XBG\nbT4+\r\n=dr9a\r\n-----END PGP SIGNATURE-----\r\n"},"main":"lib","name":"papi","author":{"name":"Silas Sewell","email":"silas@sewell.org"},"readme":"# Papi\n\nThis is a library for building HTTP API clients.\n\n * [Documentation](#documentation)\n * [Example](#example)\n * [License](#license)\n\n## Documentation\n\n * [Client](#client)\n * [Shortcuts](#shortcuts)\n\n<a name=\"client\"></a>\n### papi.Client([options])\n\nInitialize a new client.\n\nYour client should extend the Papi `Client` class and call `super(options)`\nwith the appropriate options.\n\nOptions\n\n * baseUrl (string): base URL, should not include trailing slash\n * headers (Object&lt;string, string&gt;, optional): defaults headers to include in every request\n * type (string, optional, supports: form, json, text): default request body encoding type\n * encoders (Object&lt;string, Function&gt;, optional): an object that maps a mime type to a function. The function should accept an object and return a Buffer.\n * decoders (Object&lt;string, Function&gt;, optional): an object that maps a mime type to a function. The function should accept a Buffer or string (must support both) and return an object.\n * tags (string[], optional): tags included in `_log` calls\n * timeout (number, optional): default number of milliseconds before request is aborted\n\nAdvanced options\n\n * agent (http.Agent|https.Agent, optionals): if not set uses the global agent\n * tls options: ca, cert, ciphers, clientCertEngine, crl, dhparam, ecdhCurve, honorCipherOrder, key, passphrase, pfx, rejectUnauthorized, secureOptions, secureProtocol, servername, and sessionIdContext (see [Node.js docs](https://nodejs.org/dist/latest/docs/api/tls.html#tls_tls_connect_options_callback) for details)\n\nUsage\n\n``` javascript\nconst papi = require('papi');\n\nclass GitHub extends papi.Client {\n  constructor(opts) {\n    opts = opts || {};\n    opts.baseUrl = 'https://api.github.com';\n    opts.header = { accept: 'application/vnd.github.v3+json' };\n    opts.timeout = 15 * 1000;\n\n    super(opts);\n  }\n}\n```\n\n<a name=\"client-request\"></a>\n### client.\\_request(request, [middleware...])\n\nMake an HTTP request.\n\nYour client should use this or the shortcut methods listed below to execute\nHTTP requests in your client methods.\n\nArguments\n\n * request (Object): request options\n * middlware (Function&lt;request, next&gt;, optional): middleware functions that can mutate `request.err` or `request.res`. Call `next` without arguments to continue execution, `next(err)` to break with an error, or `next(false, value)` to return immediately.\n\nRequest\n\n * path (string): request path, can include variable segments defined by curly braces (ex: `/user/{id}`)\n * method (string): request method\n * headers (Object&lt;string, string&gt;, optional): request headers\n * params (Object&lt;string, string&gt;, optional): sets variables in request path\n * query (Object&lt;string, string|string[]&gt;, optional): query parameters\n * body (Object|Buffer|Readable, optional): request body\n * type (string, optional, supports: form, json, text): request body encoding type\n * ctx (EventEmitter, optional): emit `cancel` to abort request\n * timeout (number, optional): number of milliseconds before request is aborted\n * tags (string[], optional): tags included in `_log` calls\n\nThere are also `_get`, `_head`, `_post`, `_put`, `_delete`, `_patch`,\nand `_options` shortcuts with the same method signature as `_request`.\n\nUsage\n\n``` javascript\nclass GitHub extends papi.Client {\n  constructor() {\n    // see example constructor above\n  }\n\n  async gists(username) {\n    const opts = {\n      path: '/users/{username}/gists',\n      params: { username: username },\n    };\n\n    const res = await this._get(opts);\n    return res.body;\n  }\n}\n```\n\nResult\n\n```\n[ { url: 'https://api.github.com/gists/9458207',\n...\n```\n\n### client.\\_log(tags, [data])\n\nEmit log events.\n\nArguments\n\n * tags (string[]): tags associated with event\n * data (optional): remaining arguments\n\nUsage\n\n``` javascript\nclient.on('log', function(tags) {\n  console.log({\n    tags: tags,\n    data: Array.prototype.slice.call(arguments, 1),\n  });\n});;\n\nclient._log(['github', 'gist'], 'silas');\n```\n\nResult\n\n```\n{ data: [ 'silas' ], tags: [ 'debug', 'github', 'gist' ] }\n```\n\n### client.\\_ext(event, callback)\n\nRegister an extension function.\n\nArguments\n\n * event (string): event name\n * callback (Function): function to execute at a specified point during the request\n\nUsage\n\n``` javascript\nclient._ext('onRequest', (request, next) => {\n  console.log('request', request.opts.method + ' ' + request.opts.path);\n\n  request.start = new Date();\n\n  next();\n});\n\nclient._ext('onResponse', (request, next) => {\n  const duration = new Date() - request.start;\n  const statusCode = request.res ? request.res.statusCode : 'none';\n\n  console.log('response', request.opts.method, request.opts.path, statusCode, duration + 'ms');\n\n  next();\n});\n```\n\nResult\n\n```\nrequest GET /users/{username}/gists\nresponse GET /users/{username}/gists 200 1141ms\n```\n\n### client.\\_plugin(plugin, options)\n\nRegister a plugin.\n\nArguments\n\n * plugin (Object): plugin module\n * options (Object, optional): plugin options\n\nUsage\n\n``` javascript\nclient._plugin(require('papi-retry'));\n```\n\n<a name=\"shortcuts\"></a>\n### papi.request(request, [callback...], callback)\n\nShortcuts for making one-off requests.\n\nSee [client request](#client-request) for full options list, with the exception\nthat `path` is replaced with `url`.\n\nRequest\n\n * url (string): request url (ex: `http://example.org/`)\n\nThere are also `get`, `head`, `post`, `put`, `delete` (`del`), `patch`, and\n`options` shortcuts with the same method signature as `request`.\n\nUsage\n\n``` javascript\nasync function show() {\n  const res = await papi.get('https://api.github.com/users/silas/gists');\n\n  res.body.forEach(gist => console.log(gist.url));\n}\n```\n\n\n## Example\n\n``` javascript\nconst papi = require('papi');\n\n/**\n * GitHub API client\n */\nclass GitHub extends papi.Client {\n  constructor(opts) {\n    opts = opts || {};\n\n    if (!opts.baseUrl) {\n      opts.baseUrl = 'https://api.github.com';\n    }\n    if (!opts.headers) {\n      opts.headers = {};\n    }\n    if (!opts.headers.accept) {\n      opts.headers.accept = 'application/vnd.github.v3+json';\n    }\n    if (!opts.headers['user-agent']) {\n      opts.headers['user-agent'] = 'PapiGitHub/0.1.0';\n    }\n    if (opts.tags) {\n      opts.tags = ['github'].concat(opts.tags);\n    } else {\n      opts.tags = ['github'];\n    }\n    if (!opts.timeout) {\n      opts.timeout = 60 * 1000;\n    }\n\n    super(opts);\n\n    if (opts.debug) {\n      this.on('log', console.log);\n    }\n  }\n\n  /**\n   * Get user gists\n   */\n  async gists(username) {\n    const opts = {\n      path: '/users/{username}/gists',\n      params: { username: username },\n    };\n\n    const res = await this._get(opts);\n    return res.body;\n  }\n}\n\n// Print gists for user `silas`\nasync function main() {\n  const github = new GitHub({ debug: true });\n\n  const gists = await github.gists('silas');\n\n  console.log('----');\n\n  gists.forEach(function(gist) {\n    if (gist.description) console.log(gist.description);\n  });\n}\n\nif (require.main === module) {\n  main();\n} else {\n  module.exports = GitHub;\n}\n```\n\n## License\n\nThis work is licensed under the MIT License (see the LICENSE file).\n","engines":{"node":">=10.0.0"},"gitHead":"e5ed17ace251bcae0838db68a032f087cf589d6f","license":"MIT","scripts":{"test":"jshint lib test && jscs lib test && nyc _mocha --recursive --check-leaks --globals Promise && nyc check-coverage --statements 100 --functions 100 --branches 100 --lines 100","cover":"nyc --reporter=lcov _mocha --recursive && open coverage/lcov-report/index.html"},"_npmUser":{"name":"silas","email":"silas@sewell.org"},"homepage":"https://github.com/silas/node-papi","keywords":["api","client","http","rest"],"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.","repository":{"url":"git+https://github.com/silas/node-papi.git","type":"git"},"_npmVersion":"7.5.0","description":"Build HTTP API clients","directories":{},"maintainers":[{"name":"silas","email":"silas@sewell.org"}],"_nodeVersion":"15.8.0","_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^15.1.0","jscs":"^3.0.7","nock":"^13.0.7","debug":"^4.1.1","mocha":"^8.3.0","sinon":"^9.2.4","jshint":"^2.9.5","lodash":"^4.17.10","should":"^13.2.1","request":"^2.87.0"},"_npmOperationalInternal":{"tmp":"tmp/papi_1.0.0-alpha.2_1613491066127_0.21796692635522996","host":"s3://npm-registry-packages"},"_id":"papi@1.0.0-alpha.2","version":"1.0.0-alpha.2"}