Coder Social home page Coder Social logo

minixhr's Introduction

minixhr

super simple and small cross-browser XMLHttpRequest (XHR)

USAGE

var minixhr = require('minixhr')

function response (error, data, header) {
  if (error) return console.error(error)
  console.log(data)
  console.log(header)
}

const string = JSON.stringify({ foo: 123, bar: "abc" }) // payload
const URL1 = 'https://jsonplaceholder.typicode.com/posts/1'
// @NOTE check http://requestb.in/18b4srl1?inspect after a request to inspect server
const URL2 = 'http://requestb.in/18b4srl1' // make a `http://requestb.in` to get your own

var request1 = URL1
var request2 = { // can be 'url string' or object:
  /*required*/url     : URL2,
  /*optional*/method  : 'POST',  // (defaults to `GET`)
    // can be any http method like `['GET', 'POST', 'HEAD', 'PUT', ...]` or `'JSONP'`
  /*optional*/data    : string,  // (defaults to: `undefined`)
    // can be any string, maybe formatted as e.g. <FORMDATA> or JSON e.g. '{"key":"val"}'
    // if set and no method provided, method will be set to 'POST'
  /*optional*/headers : {},      // (defaults to `{}`)
    // in case of `method === 'POST'` it defaults to:
    // {'X-Requested-With':'XMLHttpRequest','Content-Type':'application/x-www-form-urlencoded' }
  /*optional*/timeout : 1000,  // (defaults to `0`, wich means NO timeout)
    // can be any number of miliseconds, or "sync" (to make a synchronous request)
}

// EXAMPLE 1
minixhr(/*required*/request1, /*optional*/response)

// EXAMPLE 2
minixhr(/*required*/request2)

if you need to support old browsers, use version 3.1.0 or below.
Those versions still include the xhr polyfill

minixhr's People

Contributors

serapath avatar ninabreznik avatar

Stargazers

Jannis R avatar Gabriel RiCharde avatar

Watchers

James Cloos avatar Jannis R avatar  avatar

Forkers

ninabreznik

minixhr's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.