0.3.0 • Published 5 years ago

spiel-request v0.3.0

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

Spiel Request

Spiel request is a module to send ajax request. It use XmlHttpRequest

Api documentation

How use it

Set the request options by default

import {httpRequest, RequestConfig, RequestOptions, Headers} from 'spiel-request'

const headers: Headers  = {
    'Accept': 'application/json, text/*'
} 
const options: RequestConfig = {
    responseType: 'text',
    headers,
    credentials: true,
    authType: 'base64',
    auth: {
        username: 'test'
        password: '123456'
    }
    domain: 'http://localhost:3000'
}

Send your requests

const url = 'http://localhost:3000/users';
const response = httpRequest.sendRequest({
    url,
    method: 'get'
});

Upload your files

const url = 'http://localhost:3000/upload';

const blob = new Blob(['abc123'], {type: 'text/plain'});

const file = httpRequest.uploadFile({
    url,
    file: blob,
    responseType: 'json',
    name: 'test'
});

Use the XmlHttpRequest methods

const oReq = httpRequest.request

oReq.addEventListener("progress", updateProgress);
oReq.addEventListener("load", transferComplete);
oReq.addEventListener("error", transferFailed);
oReq.addEventListener("abort", transferCanceled);

oReq.open();

Run Spiel Request tests

Open two terminals, in the first execute npm run service and the another npm test

License

Spiel Request is MIT licensed. See license

0.3.0

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago