New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

xml-fetch

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml-fetch

XMLHttpRequest as fetch

latest
Source
npmnpm
Version
1.1.91
Version published
Maintainers
1
Created
Source

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));
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();

Keywords

xml-fetch

FAQs

Package last updated on 15 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts