1.1.91 • Published 5 years ago

xml-fetch v1.1.91

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

xml-fetch

XMLHttpRequest as fetch

  • supports abording
  • promise interface, but this not Promise!!!
  • get, post, delete, put

Installation

npm install --save-dev xml-fetch

Options

type TOptions = {
    method?: string, // Метод запроса
    async?: boolean, // Тип запроса
    headers?: { [x: string]: string }, // Заголовки
    timeout?: number, // Время жизни запроса
    timeoutError?: string // Текст ошибки по истечению timeout
};

Usage

"simple get"

Methods in 'http', return new instance xml-fetch

import { http } from 'xml-fetch';

const API_URL = 'https://you-api.com'; const method = 'you-method'; const query = { param1: 'param1', param2: 'param2' };

http.get(${API_URL}/${method}/}, { query }) .then(response => console.log(response)) .catch(error => console.log(error));

---
```js
import XmlFetch from 'xml-fetch';

xmlFetch.get(`${API_URL}/${method}/`}, { query })
    .then(response => console.log(response))
    .catch(error => console.log(error));

"simple post"

http.post(`${API_URL}/${method}/`}, { data })
    .then(response => console.log(response))
    .catch(error => console.log(error));

Other methods

type TRequestParams = {
    files?: { [x: string]: [] }, // Массив файлов
    data?: { [x: string]: []|string } // Данные
};

http.get(url: string, { ...params }: object, options?: TOptions): XmlFetch;
http.post(url: string, { ...params }: TRequestParams, options?: TOptions): XmlFetch;
http.put(url: string, { ...params }: TRequestParams,  options?: TOptions): XmlFetch;
http.delete(url: string, { ...params }: object,  options?: TOptions): XmlFetch;

Aborting

let request = http.get(`${API_URL}/${method}/`}, { query })
    .then(response => console.log(response))
    .catch(error => console.log(error));

request.abort();
1.1.91

5 years ago

1.11.0

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago