UNPKG

@bbc/http-transport

Version:

A flexible, modular REST client built for ease-of-use and resilience.

931 lines (240 loc) 12 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>HttpTransportBuilder - Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc.css"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="HttpTransportBuilder.html">HttpTransportBuilder</a><ul class='methods'><li data-type='method'><a href="HttpTransportBuilder.html#createClient">createClient</a></li><li data-type='method'><a href="HttpTransportBuilder.html#retries">retries</a></li><li data-type='method'><a href="HttpTransportBuilder.html#retryDelay">retryDelay</a></li><li data-type='method'><a href="HttpTransportBuilder.html#use">use</a></li><li data-type='method'><a href="HttpTransportBuilder.html#userAgent">userAgent</a></li></ul></li><li><a href="HttpTransportClient.html">HttpTransportClient</a><ul class='methods'><li data-type='method'><a href="HttpTransportClient.html#asBody">asBody</a></li><li data-type='method'><a href="HttpTransportClient.html#asResponse">asResponse</a></li><li data-type='method'><a href="HttpTransportClient.html#delete">delete</a></li><li data-type='method'><a href="HttpTransportClient.html#get">get</a></li><li data-type='method'><a href="HttpTransportClient.html#head">head</a></li><li data-type='method'><a href="HttpTransportClient.html#headers">headers</a></li><li data-type='method'><a href="HttpTransportClient.html#patch">patch</a></li><li data-type='method'><a href="HttpTransportClient.html#post">post</a></li><li data-type='method'><a href="HttpTransportClient.html#put">put</a></li><li data-type='method'><a href="HttpTransportClient.html#query">query</a></li><li data-type='method'><a href="HttpTransportClient.html#redirect">redirect</a></li><li data-type='method'><a href="HttpTransportClient.html#retry">retry</a></li><li data-type='method'><a href="HttpTransportClient.html#retryDelay">retryDelay</a></li><li data-type='method'><a href="HttpTransportClient.html#timeout">timeout</a></li><li data-type='method'><a href="HttpTransportClient.html#use">use</a></li></ul></li></ul> </nav> <div id="main"> <h1 class="page-title">HttpTransportBuilder</h1> <section> <header> <h2> HttpTransportBuilder </h2> </header> <article> <div class="container-overview"> <h4 class="name" id="HttpTransportBuilder"><span class="type-signature"></span>new HttpTransportBuilder<span class="signature">(transport)</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="builder.js.html">builder.js</a>, <a href="builder.js.html#line12">line 12</a> </li></ul></dd> </dl> <div class="description"> <p>Configures HttpTransport client</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>transport</code></td> <td class="type"> <span class="param-type">Transport</span> </td> <td class="description last"><p>Transport instance.</p></td> </tr> </tbody> </table> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="createClient"><span class="type-signature"></span>createClient<span class="signature">()</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="builder.js.html">builder.js</a>, <a href="builder.js.html#line98">line 98</a> </li></ul></dd> </dl> <div class="description"> <p>Instantiates a HttpTransport</p> </div> <h5>Example</h5> <pre class="prettyprint"><code>const client = httpTransport.createClient();</code></pre> <h5>Returns:</h5> <div class="param-desc"> <p>a HttpTransport instance</p> </div> <h4 class="name" id="retries"><span class="type-signature"></span>retries<span class="signature">(retries)</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="builder.js.html">builder.js</a>, <a href="builder.js.html#line51">line 51</a> </li></ul></dd> </dl> <div class="description"> <p>Set the default number of retries</p> </div> <h5>Example</h5> <pre class="prettyprint"><code>const httpTransport = require('@bbc/http-transport'); const builder = httpTransport.createBuilder(); builder.retries(5);</code></pre> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>retries</code></td> <td class="type"> <span class="param-type">integer</span> </td> <td class="description last"><p>number of retry attempts</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>a HttpTransportBuilder instance</p> </div> <h4 class="name" id="retryDelay"><span class="type-signature"></span>retryDelay<span class="signature">(delay)</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="builder.js.html">builder.js</a>, <a href="builder.js.html#line67">line 67</a> </li></ul></dd> </dl> <div class="description"> <p>default time delay between retries</p> </div> <h5>Example</h5> <pre class="prettyprint"><code>const httpTransport = require('@bbc/http-transport'); const builder = httpTransport.createBuilder(); builder.retryDelay(1000);</code></pre> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>delay</code></td> <td class="type"> <span class="param-type">integer</span> </td> <td class="description last"><p>delay time in ms</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>a HttpTransportBuilder instance</p> </div> <h4 class="name" id="use"><span class="type-signature"></span>use<span class="signature">(fn)</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="builder.js.html">builder.js</a>, <a href="builder.js.html#line84">line 84</a> </li></ul></dd> </dl> <div class="description"> <p>Registers a global plugin, which is used for all requests</p> </div> <h5>Example</h5> <pre class="prettyprint"><code>const toError = require('@bbc/http-transport-errors'); const httpTransport = require('@bbc/http-transport'); const client = httpTransport.createClient(); client.useGlobal(toError(404));</code></pre> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>fn</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"><p>a global plugin</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>a HttpTransportBuilder instance</p> </div> <h4 class="name" id="userAgent"><span class="type-signature"></span>userAgent<span class="signature">(agent)</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="builder.js.html">builder.js</a>, <a href="builder.js.html#line35">line 35</a> </li></ul></dd> </dl> <div class="description"> <p>Sets a default user agent</p> </div> <h5>Example</h5> <pre class="prettyprint"><code>const httpTransport = require('@bbc/http-transport'); const builder = httpTransport.createBuilder(); builder.userAgent('some-user-agent');</code></pre> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>agent</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>user agent</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>a HttpTransportBuilder instance</p> </div> </article> </section> </div> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Mon Feb 19 2024 16:02:59 GMT+0100 (Central European Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. </footer> <script>prettyPrint();</script> <script src="scripts/linenumber.js"></script> </body> </html>