@increments/request

Minimalistic XHR wrapper

Usage no npm install needed!

<script type="module">
  import incrementsRequest from 'https://cdn.skypack.dev/@increments/request';
</script>

README

@increments/request

NPM version Build Status Maintainability Test Coverage Stable Release Size

Minimalistic XHR wrapper. Zero dependency.

Installation

If your project is using npm, you can install @increments/request package by npm command:

npm install --save @increments/request
# or
yarn add @increments/request

Distribution files

  • dist/index.js - The CommonJS version of this package. (default)
  • dist/index.es.js - The native modules version of this package.
  • dist/request.es5.js - ES5 / UMD version of this package. This version exports itself to window.Request.

Synopsis

import { request } from "@increments/request"

request("POST", "/api/endpoint", {
  headers: {
    "Accept": "application/json",
    "Content-Type": "application/json;charset=UTF-8"
  },
  data: requestPayload
}).then(response => {
  //
}).catch(error => {
  //
})

TypeScript

// Declare type of response.data
request<{ users: { name: string }[] }>("GET", "/users")
  .then(response => {
    console.log(response.data.users[0].name) // Show first user's name.
  })