An AngularJS service wrapping Stars Wars API (swapi.co), inspired by SWAPI-Wrapper by Raymond Camden.
The service is completly promise oriented and offers access to swapi.co from AngularJS applications.
The xyz.angular.swapi modules comes with one angular constant swapiEndpoints, used internally by the main service swapiService.
To use the service just import the module in your AngularJS application and inject the swapiService whre required.
In your javascript:
// include the module
angular.module('myStarWarsApp', ['xyz.angular.swapi']).
controller('jediController', ['swapiService',
function($scope, swapiService) {
// get luke skywalker data
swapiService.peope('1').
then(function(lukeData){
$scope.luke = lukeData;
});
}
])Inside your view template:
<ul>
<li>Name: {{luke.name}}</li>
<li>Eyes color: {{luke.eye_color}}</li>
<li>Skin color: {{luke.skin_color}}</li>
</ul>The module can be installed from bower:
$ bower install xyz-angular-swapi --save
from npm:
$ npm install xyz-angular-swapi --save
or downloading directly the minified version.
For every end-point exposed by swapi.com 3 methods are available:
- get specific resource by type and id
- get all resources for a given type
- get JSON Schema for a given type
Complete API, all methods return a promise.
film(id)return one filmfilms([page])return all films paginated. If no page is passed defaults to 1.filmSchema()return the JSON Schema for thefilmresource
person(id)return one personpeople([page])return all people paginated. If no page is passed defaults to 1.peopleSchema()return the JSON Schema for thepeopleresource
planet(id)return one planetplanets([page])return all planets paginated. If no page is passed defaults to 1.planetSchema()return the JSON Schema for theplanetresource
singleSpecies(id)return one speciesspecies([page])return all species paginated. If no page is passed defaults to 1.speciesSchema()return the JSON Schema for thespeciesresource
starship(id)return one starshipstarships([page])return all starships paginated. If no page is passed defaults to 1.starshipSchema()return the JSON Schema for thestarshipresource
vehicle(id)return one vehiclevehicles([page])return all vehicles paginated. If no page is passed defaults to 1.vehicleSchema()return the JSON Schema for thevehicleresource
resources()return the available REST resourcesresource(url)load a valid REST resource url, not only from swapy.com
An integration with the local storage has been already done but has external dependencies. Will be added as soon as we can remove all dependencies.