Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/juliendargelos/open-request-js

Simply send http requests.
https://github.com/juliendargelos/open-request-js

Last synced: 4 days ago
JSON representation

Simply send http requests.

Awesome Lists containing this project

README

        

# Open Request JS 📣
[![npm version](https://badge.fury.io/js/open-request-js.svg)](https://badge.fury.io/js/open-request-js)
[![Maintainability](https://api.codeclimate.com/v1/badges/98eed689838832855d7b/maintainability)](https://codeclimate.com/github/juliendargelos/open-request-js/maintainability)

Simply send http requests.

## Install

```
npm install open-request-js
```

## Usage

```javascript
var Request = require('open-request-js'); // To be used from node.
var Request = require('open-request-js/dist'); // To be used from browser.

var request = new Request('/users/:id?lang=en');

request.url.path.id = 4;
request.url.parameters.lang = 'fr';
request.url.string;
// => "/users/4?lang=fr"

request.send().then(response => console.log(response.json));
```

> Why does the require statement depend on wether it's meant to be use from node or from browser?

Because from node, `Request` needs to require [XMLHttpRequest](https://www.npmjs.com/package/xmlhttprequest) while it already exists in the browser.
By the way, you will not be able to use [`html`](#HttpResponse+html) and [`xml`](#HttpResponse+xml) [`HttpResponse`](#HttpResponse) accessors from node neither because (at the moment) they depend on browser-exclusive APIs.

{{>main}}