You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
6.3 KiB

  1. <a href="http://promisesaplus.com/">
  2. <img src="https://promises-aplus.github.io/promises-spec/assets/logo-small.png" align="right" alt="Promises/A+ logo" />
  3. </a>
  4. # request-promise-core
  5. [![Gitter](https://img.shields.io/badge/gitter-join_chat-blue.svg?style=flat-square&maxAge=2592000)](https://gitter.im/request/request-promise?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
  6. [![Build Status](https://img.shields.io/travis/request/promise-core/master.svg?style=flat-square&maxAge=2592000)](https://travis-ci.org/request/promise-core)
  7. [![Coverage Status](https://img.shields.io/coveralls/request/promise-core.svg?style=flat-square&maxAge=2592000)](https://coveralls.io/r/request/promise-core)
  8. [![Dependency Status](https://img.shields.io/david/request/promise-core.svg?style=flat-square&maxAge=2592000)](https://david-dm.org/request/promise-core)
  9. [![Known Vulnerabilities](https://snyk.io/test/npm/promise-core/badge.svg?style=flat-square&maxAge=2592000)](https://snyk.io/test/npm/promise-core)
  10. This package is the core for the following packages:
  11. - [`request-promise`](https://github.com/request/request-promise)
  12. - [`request-promise-any`](https://github.com/request/request-promise-any)
  13. - [`request-promise-bluebird`](https://github.com/request/request-promise-bluebird)
  14. - [`request-promise-native`](https://github.com/request/request-promise-native)
  15. `request-promise-core` contains the core logic to add Promise support to [`request`](https://github.com/request/request).
  16. Please use one of the libraries above. It is only recommended to use this library directly, if you have very specific requirements.
  17. ## Installation for `request@^2.34`
  18. This module is installed via npm:
  19. ```
  20. npm install --save request
  21. npm install --save request-promise-core
  22. ```
  23. `request` is defined as a peer-dependency and thus has to be installed separately.
  24. ## Usage for `request@^2.34`
  25. ``` js
  26. // 1. Load the request library
  27. // Only use a direct require if you are 100% sure that:
  28. // - Your project does not use request directly. That is without the Promise capabilities by calling require('request').
  29. // - Any of the installed libraries use request.
  30. // ...because Request's prototype will be patched in step 2.
  31. /* var request = require('request'); */
  32. // Instead use:
  33. var stealthyRequire = require('stealthy-require');
  34. var request = stealthyRequire(require.cache, function () {
  35. return require('request');
  36. });
  37. // 2. Add Promise support to request
  38. var configure = require('request-promise-core/configure/request2');
  39. configure({
  40. request: request,
  41. // Pass your favorite ES6-compatible promise implementation
  42. PromiseImpl: Promise,
  43. // Expose all methods of the promise instance you want to call on the request(...) call
  44. expose: [
  45. 'then', // Allows to use request(...).then(...)
  46. 'catch', // Allows to use request(...).catch(...)
  47. 'promise' // Allows to use request(...).promise() which returns the promise instance
  48. ],
  49. // Optional: Pass a callback that is called within the Promise constructor
  50. constructorMixin: function (resolve, reject) {
  51. // `this` is the request object
  52. // Additional arguments may be passed depending on the PromiseImpl used
  53. }
  54. });
  55. // 3. Use request with its promise capabilities
  56. // E.g. crawl a web page:
  57. request('http://www.google.com')
  58. .then(function (htmlString) {
  59. // Process html...
  60. })
  61. .catch(function (err) {
  62. // Crawling failed...
  63. });
  64. ```
  65. ## Installation and Usage for `request@next`
  66. [Request Next](https://github.com/request/request/issues/1982) is still in alpha. However, `request-promise-core` is already designed to be compatible and ships with a configuration helper – `require('request-promise-core/configure/request-next')` – that is [used by `request-promise`](https://github.com/request/request-promise/blob/next/lib/rp.js) in its "next" branch.
  67. ## Contributing
  68. To set up your development environment:
  69. 1. clone the repo to your desktop,
  70. 2. in the shell `cd` to the main folder,
  71. 3. hit `npm install`,
  72. 4. hit `npm install gulp -g` if you haven't installed gulp globally yet, and
  73. 5. run `gulp dev`. (Or run `node ./node_modules/.bin/gulp dev` if you don't want to install gulp globally.)
  74. `gulp dev` watches all source files and if you save some changes it will lint the code and execute all tests. The test coverage report can be viewed from `./coverage/lcov-report/index.html`.
  75. If you want to debug a test you should use `gulp test-without-coverage` to run all tests without obscuring the code by the test coverage instrumentation.
  76. ## Change History
  77. - 1.1.4 (2020-07-21)
  78. - Security fix: bumped `lodash` to `^4.17.19` following [this advisory](https://www.npmjs.com/advisories/1523).
  79. - 1.1.3 (2019-11-03)
  80. - Security fix: bumped `lodash` to `^4.17.15`. See [vulnerabilty reports](https://snyk.io/vuln/search?q=lodash&type=npm).
  81. *(Thanks to @daniel-nagy for pull request [#20](https://github.com/request/promise-core/pull/20) and thanks to @quetzaluz for reporting this in issue [#21](https://github.com/request/promise-core/issues/21).)*
  82. - 1.1.2 (2019-02-14)
  83. - Security fix: bumped `lodash` to `^4.17.11`. See [vulnerabilty reports](https://snyk.io/vuln/search?q=lodash&type=npm).
  84. *(Thanks to @lucaswillering and @sam-warren-finnair for reporting this in issues [#12](https://github.com/request/promise-core/issues/12) and [#13](https://github.com/request/promise-core/issues/13) and thanks to @Alec321 for pull request [#14](https://github.com/request/promise-core/pull/14).)*
  85. - 1.1.1 (2016-08-08)
  86. - Renamed package to `request-promise-core` because there were [too](https://github.com/request/request-promise/issues/137) [many](https://github.com/request/request-promise/issues/141) issues with the scoped package name `@request/promise-core`
  87. - 1.1.0 (2016-07-30)
  88. - Added `constructorMixin` option to enable [request/request-promise#123](https://github.com/request/request-promise/pull/123)
  89. - 1.0.0 (2016-07-15)
  90. - All tests green, ready for prime time
  91. - 1.0.0-rc.1 (2016-07-10)
  92. - Reimplementation of core logic based on `request-promise@3.0.0`
  93. - Plus `transform2xxOnly` option (fixes [request/request-promise#131](https://github.com/request/request-promise/issues/131))
  94. ## License (ISC)
  95. In case you never heard about the [ISC license](http://en.wikipedia.org/wiki/ISC_license) it is functionally equivalent to the MIT license.
  96. See the [LICENSE file](LICENSE) for details.