https://github.com/hubgit/web-resource
A JavaScript interface for fetching HTTP resources from the web
https://github.com/hubgit/web-resource
Last synced: 4 months ago
JSON representation
A JavaScript interface for fetching HTTP resources from the web
- Host: GitHub
- URL: https://github.com/hubgit/web-resource
- Owner: hubgit
- Created: 2014-05-07T11:47:16.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2016-01-14T11:37:50.000Z (about 10 years ago)
- Last Synced: 2025-10-09T01:25:33.384Z (4 months ago)
- Language: JavaScript
- Homepage: http://git.macropus.org/web-resource/demo.html
- Size: 48.8 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# web-resource
A JavaScript interface for fetching HTTP resources from the web.
## Features
* Handles rate-limiting, using HTTP response headers.
* Makes 1 request at a time, per domain (configurable).
* Pause/resume for queues.
## Demonstration
[A very simple demo](http://git.macropus.org/web-resource/demo.html)
## Usage
```bash
bower install hubgit/web-resource --save
```
```html
```
or
```html
```
## Examples
### Fetch a resource as JSON
```javascript
Resource('https://api.spotify.com/v1/artists/5Al98vDcGka3JcJ1WlZYoN').get('json').then(function(data) {
// do something with the data
});
```
### Fetch a paginated collection, with query parameters
```javascript
Collection('https://api.spotify.com/v1/search', {
type: 'artist',
q: 'artist:"Cows"'
}).get('json', {
// select the array of items
items: function(data) {
return data.artists.items;
},
// select the URL of the next chunk
next: function(data) {
return data.artists.next;
}
}).then(function(items) {
// do something with the items
});
```
## CORS
Override `Request.prototype.prepare` to manipulate the URL and pass the request through a local proxy (e.g. for local caching, or to add CORS headers).