Angular2 service for Star Wars API
Switch branches/tags
Clone or download
Latest commit 4aece1b Jul 8, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example Update response.component.ts Apr 5, 2017
.gitattributes 👾 Added .gitattributes & .gitignore files Aug 4, 2016
.gitignore package.json update Aug 5, 2016
README.md Update README.md Aug 22, 2016
index.js getSchema + working example Aug 6, 2016
index.js.map getSchema + working example Aug 6, 2016
index.ts Update index.ts Jul 7, 2017
package.json getSchema + working example Aug 6, 2016
tsconfig.json update README Aug 6, 2016

README.md

Angular2 Service for Star Wars API

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 your map object in system.config.js
 var map = {
   'app':         'app',
   ...
   'ng2-swapi':   'node_modules/ng2-swapi'
 };
  • Add ng2-swapi package in your packages object in system.config.js
  var packages = {
    'app':       { main: 'main.js',  defaultExtension: 'js' },
    ...
    'ng2-swapi': { main: 'index.js', defaultExtension: 'js' }
  };

Using

  1. Import SwapiService Component
    import { SwapiService } from './ng2-swapi';
  1. Add it in the provider array of your component
    @Component({
        selector: 'my-custom-selector',
        templateUrl: 'my-componet-template.component.html',
        providers: [ SwapiService ]
    })
  1. Add an argument of type SwapiService to your class constructor
export class myComponent {
      constructor (private swapi: SwapiService) {}
    }
  1. 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 call
  • err 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 number
  • wookiee boolean (default: false) - wookiee translations

Returns

  • res object - contain the response of the call
  • err 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 resource
  • wookiee boolean (default: false) - wookiee translations

Returns

  • res object - contain the response of the call
  • err string - contain the error if something wrong occurred

Original documentation

Original documentation of Star Wars API by Paul Hallet

at https://swapi.co/documentation

Designer

Gianmaria Leoni

Full working Example

View README in example\ folder

ToDo

  • Testing