https://github.com/wzhudev/pjsonp
:traffic_light: jsonp with elegent Promise API.
https://github.com/wzhudev/pjsonp
jsonp jsonp-request promise-api
Last synced: 6 months ago
JSON representation
:traffic_light: jsonp with elegent Promise API.
- Host: GitHub
- URL: https://github.com/wzhudev/pjsonp
- Owner: wzhudev
- License: mit
- Created: 2018-03-28T07:47:02.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-09T13:53:37.000Z (about 8 years ago)
- Last Synced: 2025-03-15T06:52:08.619Z (over 1 year ago)
- Topics: jsonp, jsonp-request, promise-api
- Language: HTML
- Homepage: https://www.npmjs.com/package/pjsonp
- Size: 41 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pjsonp
> jsonp with elegent Promise API.
## Installation
```sh
npm install pjsonp --save
```
## API
```js
const pjsonp = require('path/to/pjsonp')
const url = 'http://jsfiddle.net/echo/jsonp/'
const params = {
beep: 'boop',
yo: 'dawg'
}
const options = {
timeout: 1,
name: 'namedCb'
}
pjsonp(url, params, options)
.then(data => {
/* deal with the data you just fetched! */
})
.catch(err => {
/* timeout err by default */
})
```
* `url`: url to fetch data. It should look like `http://somehostname[:someport]/to/some/path[?with=true&orWithoutQueries=false]`
* `params` (optional): an plain object that contains parameters. Considering jsonp is all about 'GET', promise-jsonp will parse them into `url` for you. But if you don't have parameters or have enclosed them in `url`, that's fine. Just ignore `params`.
* `options` (optional, but you can't just provide `params` without `options`):
* `prefix`: prefix of jsonp callback function. Default: `__jp`.
* `timeout`: literal meaning. Default: `60000`, in milliseconds.
* `name`: the name of callback function. If set, `prefix` would be invalid. Default: `undefined`.
* `param`: name of the query string parameter to specify the callback. Default: `callback`.
## Test
~~Test with Jest. Run `npm run test`.~~
**Due to some unknown problems, I can't test it with Jest. So I wrote a `.html` to test it in browsers manually. Anyone knows why Jest just won't work?**
## LICENSE
MIT