ng2-swapi
v1.0.0-rc.11
Published
Angular2 Service for Star Wars API
Downloads
39
Readme
Angular2 Service for Star Wars API
ATTENTION! Service & Documentation still in progress
It uses Star Wars API by Paul Hallet
Installation
Run npm install ng2-swapi --save
to install and add to your dependencies
Installation optional
Depending on your actual settings you may need to:
- Add
ng2-swapi
path in yourmap
object insystem.config.js
var map = {
'app': 'app',
...
'ng2-swapi': 'node_modules/ng2-swapi'
};
- Add
ng2-swapi
package in yourpackages
object insystem.config.js
var packages = { 'app': { main: 'main.js', defaultExtension: 'js' }, ... 'ng2-swapi': { main: 'index.js', defaultExtension: 'js' } };
Using
- Import SwapiService Component
import { SwapiService } from './ng2-swapi';
- Add it in the provider array of your component
@Component({
selector: 'my-custom-selector',
templateUrl: 'my-componet-template.component.html',
providers: [ SwapiService ]
})
- Add an argument of type
SwapiService
to your class constructor
export class myComponent {
constructor (private swapi: SwapiService) {}
}
- Call the desired method (other available methods)
// Example of using
// Correspond to http://swapi.co/api/people/3/
this.swapi.getPerson(3).subscribe(res => {},err => {});
//Response
res = {
"name": "R2-D2",
"height": "96",
"mass": "32",
"hair_color": "n/a",
"skin_color": "white, blue",
"eye_color": "red",
"birth_year": "33BBY",
...
Methods available
Get Root
swapi.getRoot(wookiee).subscribe(res => {},err => {});
Attributes:
wookiee
boolean (default: false) - wookiee translations
Returns
res
object - contain the response of the callerr
string - contain the error if something wrong occurred
Get People / Get Films / Get Starships / Get Vehicles / Get Species / Get Planets
swapi.getPeople(page, wookiee).subscribe(res => {},err => {});
swapi.getFilms(page, wookiee).subscribe(res => {},err => {});
swapi.getStarships(page, wookiee).subscribe(res => {},err => {});
swapi.getVehicles(page, wookiee).subscribe(res => {},err => {});
swapi.getSpecies(page, wookiee).subscribe(res => {},err => {});
swapi.getPlanets(page, wookiee).subscribe(res => {},err => {});
Attributes:
page
number (default: null) - page numberwookiee
boolean (default: false) - wookiee translations
Returns
res
object - contain the response of the callerr
string - contain the error if something wrong occurred
Get Person / Get Film / Get Starship / Get Vehicle / Get Specie / Get Planet
swapi.getPeople(id, wookiee).subscribe(res => {},err => {});
swapi.getFilms(id, wookiee).subscribe(res => {},err => {});
swapi.getStarships(id, wookiee).subscribe(res => {},err => {});
swapi.getVehicles(id, wookiee).subscribe(res => {},err => {});
swapi.getSpecies(id, wookiee).subscribe(res => {},err => {});
swapi.getPlanets(id, wookiee).subscribe(res => {},err => {});
Attributes:
id
number (mandatory) -:id
of the resourcewookiee
boolean (default: false) - wookiee translations
Returns
res
object - contain the response of the callerr
string - contain the error if something wrong occurred
Original documentation
Original documentation at https://swapi.co/documentation.
AngularJS version here by unshift-devs
Designer
ToDo
- Testing