Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/juliendargelos/open-request-js
- Owner: juliendargelos
- Created: 2017-12-02T20:18:41.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-18T19:30:33.000Z (almost 7 years ago)
- Last Synced: 2024-04-29T13:03:28.943Z (9 months ago)
- Language: JavaScript
- Size: 33.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.hbs
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}}