A simple wrapper for XMLHttpRequest

Usage no npm install needed!

<script type="module">
  import easyHttpRequest from 'https://cdn.skypack.dev/easy-http-request';


Easy Http Request

A simple wrapper for XMLHttpRequest


npm install easy-http-request


Include easy-http-request in your project

var HttpRequest = require('easy-http-request');

Create a new instance of the class with the following parameters

var request = new HttpRequest("POST", "http://httpbin.org/anything", "text/html; charset=utf-8");

Optionally add aditional headers

request.setRequestHeader("Authorization", "Basic " + base64string);

Optionally add a timeout (value specified is miliseconds)


Initiate the request with optional post data

request.getResponse("This is an example string").then(function(resp){

The response will have the following values:

  • success: true if the call was successfull and false if there was a problem
  • data: contains the returned data if successfull and the request object if there was a problem
  • message: "Success" if the call was successfull, a detailed error message if there was a problem (e.g. "Request Timed Out")