Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeremenichelli/cormoran
Light weight library to manage JSONP calls using Promises
https://github.com/jeremenichelli/cormoran
Last synced: 16 days ago
JSON representation
Light weight library to manage JSONP calls using Promises
- Host: GitHub
- URL: https://github.com/jeremenichelli/cormoran
- Owner: jeremenichelli
- License: mit
- Created: 2016-02-10T19:46:42.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-06-08T19:04:27.000Z (over 8 years ago)
- Last Synced: 2024-10-11T13:34:40.293Z (about 1 month ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cormoran [![Build Status](https://travis-ci.org/jeremenichelli/cormoran.svg)](https://travis-ci.org/jeremenichelli/cormoran)
Light weight library to manage JSONP calls using Promises
## Install
Download the distribution version and include it on your web project or add it as a dependency
```sh
npm install cormoran --save
```## Use
If you know how Promises in JavaScript work and what is a JSONP call, then you don't need much else.
Require the package or use the global `cormoran` namespace and run `get`passing a *url*, pipe a `then` statement to handle the data you've received and `catch` just in case something goes wrong.
```js
var cormoran = require('cormoran');cormoran
.get('https://api.github.com/users/jeremenichelli')
.then(function(data) {
console.log(data);
})
.catch(function(e) {
console.error(e);
});
```## Configuration
As the callback name and query can changed depending on the API you're trying to reach you can change both of them running this two methods before using the `get` method.
### naming
```js
cormoran.naming('JSONP_CALLBACK');
```### query
```js
cormoran.query('?callback');
```_Following the first example the final url would be *https://api.github.com/users/jeremenichelli?callback=JSONP_CALLBACK0*, a number will be added at the end of every callback name to make them unique._
## Notes
Since this library relies on Promises remember to include a polyfill for browsers which don't support this feature. I recommend this one https://github.com/jakearchibald/es6-promise developed by Jake Archibald.