davidjpfeiffer / http-service

A lightweight Javascript service for making HTTP requests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Javascript HTTP Service

A lightweight Javascript service for making HTTP requests

About

A simple and lightweight JavaScript service for making asynchronous http requests to a web server. The service has built in support for GET, PUT, POST, and DELETE requests. Each of these request types are exposed as methods on the service, all of which return a promise.

To simplify the requests, default headers are specified in the service and are automatically added to each request. If you would like to specify unique headers for each request, you can modify the service to take in a headers object as an extra parameter.

Usage

If the request is successful, the code below will print a list of people. If it is not successful, an error message will be logged to the console.

window.httpService.get('api/v1/people')
.then(onSuccess)
.catch(onError);

function onSuccess(response) {
  response.forEach(person => {
    console.log(person + ' ');
  });
}

function onError(response) {
  console.log('Something went wrong.');
}

About

A lightweight Javascript service for making HTTP requests

License:Apache License 2.0


Languages

Language:JavaScript 100.0%