[!!!] This repository has been deprecated, we suggest to use https://github.com/docomodigital/js-fetcher instead
- retry
- attempts
- promise based
- npm run build
- npm run test
- npm run test:watch // run tests while typing
- npm run documentation // generate docs folder with .html, append docs to the readme.md
- npm version patch|minor|major This will generate the docs/ and dist/
an http class to make requests over the net with retry and interval between them
Parameters
requestParams
object object where you can specify the options of the requestrequestParams.type
[string] the type of the request: possible values POST, GET, PUT, DELETE and JSONP (optional, defaultGET
)requestParams.url
string the url to request forrequestParams.headers
[object] the headers object (optional, default{}
)requestParams.timeout
[string] the timeout of the request in ms (optional, default2000
)requestParams.attempt
[string] attempts. if it fails for some reason retry (optional, default1
)requestParams.retryAfter
[number] the interval between requests in ms: 500 for example (optional, default0
)requestParams.async
[boolean] the request could be synchrounous, default async (optional, defaulttrue
)
options
callback
[function] onend callback (optional, defaultfunction(){}
)
Examples
<pre>
npm install --save http-francis
import { Http, getImageRaw, JSONPRequest } from 'http-francis';
OR
var Http = require("http-francis").Http;
OR
<script src='http-francis.js'></script>
// in global case window['http-francis'].Http
var getTask = new Http({
method: "GET",
url: "https://someimageurl/image.png",
responseType: "blob",
mimeType: "image/png",
onProgress:(percentage)=>{
// there must be Content-Length header in the response to get the right percentage
// otherwise percentage is a NaN
}
});
getTask.promise.then((response) => {
var imgTag = document.createElement("img");
imgTag.src = response[0];
document.body.appendChild(imgTag);
});
</pre>
parseResponse
Parameters
xhr
XMLHttpRequest parse
Returns array [responseData, statusCode, xhr]
getImageRaw from a specific url
Parameters
Returns Promise<(Blob | ArrayBuffer | Error)>
Make a jsonp request, remember only GET The function create a tag script and append a callback param in querystring. The promise will be reject after 3s if the url fail to respond
Parameters
url
String the url with querystring but without &callback at the end or &functiontimeout
[Number](default 3000) ms range for the response
Examples
<pre>
request = new JSONPRequest("http://www.someapi.com/asd?somequery=1");
request.then((data) => {});
</pre>
Returns Promise<(Object | String)>
getJSON
Parameters
url
String for example http://jsonplaceholder.typicode.com/comments?postId=1
Returns Promise the string error is the statuscode
an http module to make requests over the net with retry and interval between them