Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/acombes/swapi-js
Library using the Star Wars API by Paul Hallett at http://swapi.co/
https://github.com/acombes/swapi-js
Last synced: about 2 months ago
JSON representation
Library using the Star Wars API by Paul Hallett at http://swapi.co/
- Host: GitHub
- URL: https://github.com/acombes/swapi-js
- Owner: Acombes
- Created: 2015-02-17T11:31:24.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-02-18T21:01:23.000Z (almost 10 years ago)
- Last Synced: 2023-04-10T01:04:35.896Z (over 1 year ago)
- Language: JavaScript
- Size: 164 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SWAPI-js
Library based on the [Star Wars API](http://swapi.co/) by Paul Hallett
## Careful
Using this library should be pretty simple as long as the API you want to use exposes itself somewhere. The description should expose something like that:```
{
"people": "http://swapi.co/api/people/",
"planets": "http://swapi.co/api/planets/",
"films": "http://swapi.co/api/films/",
"species": "http://swapi.co/api/species/",
"vehicles": "http://swapi.co/api/vehicles/",
"starships": "http://swapi.co/api/starships/"
}
```## Get started
1. Initialize your instance using only the URL where the API is described:
var myApi = new Swapi('http://swapi.co/api/');
2. You can now use your API *almost* as you wish. Since that the instance is initialized using the description given when asked directly to the API, we need to compose with AJAX's asynchronous ways. That's why when you actually use your instance, you should wrap the calls in its `.ready()` method.
myApi.ready(function () {
// Here, i can be sure that my API instance is ready to be used
// Now, I can do whatever i want !
});
It works in the same way as JQuery's `.ready()` method.## What is available ?
For each key word exposed in the API's description, your intance will have 3 methods available:
* `get[KeyWord](id, success, error)` : retrieves a single result from the given `id` and passes it to the `success` callback
* `getAll[KeyWord](success, error)` : retrieves all results and passes them to the `success` callback
* `getAll[KeyWord](page, success, error)` : retrieves a single page of results and passes it to the `success` callbackAll `error` arguments are error callbacks and are optional.
It is possible to handle several APIs at once, they will be completely independant of one another.
# Evolution
Using ES6's promises could be a blast