angular2-swapi
Angular2Swapi library will help developers building angular and ionic applications which are using data from StarWars API.
Installation
To install this library run:
npm install angular2-swapi --save
Bootstrap
Import Angular2SwapiModule in your app.module.ts file and add it into imports array:
;; ; ;
Angular2SwapiService
angular2-swapi is actually service library providing methods to call https://swapi.co and return resources based on your query. You can say it is HTTP client for StarWars API.
List of available methods
People
Method | Parameters | Return | Description |
---|---|---|---|
getPeople() | page?: number | Observable<People[]> | Returns list of people as Observable |
getPeopleById(id) | id: number | Observable< People > | Returns character by id |
searchPeople(name) | name: string | Observable<People[]> | Search people by name |
Films
Method | Parameters | Return | Description |
---|---|---|---|
getFilms() | page?: number | Observable<Film[]> | Returns list of films as Observable |
getFilm(id) | id: number | Observable < Film > | Returns film by id |
searchFilms(title) | title: string | Observable<Film[]> | Search films by title |
Starships
Method | Parameters | Return | Description |
---|---|---|---|
getStarships(page) | page?: number | Observable<Starship[]> | Return list of starships as Observable |
getStarship(id) | id: number | Observable< Starship > | Return starship by id |
searchStarships(name) | name: string | Observable<Starship[]> | Search starships by name or model |
Vehicles
Method | Parameters | Return | Description |
---|---|---|---|
getVehicles(page) | page?: number | Observable<Vehicle[]> | Return list of vehicles as Observable |
getVehicle(id) | id: number | Observable< Vehicle > | Returns vehicle by id |
searchVehicles(name) | name: string | Observable<Vehicle[]> | Search vehicles by name or model |
Species
Method | Parameters | Return | Description |
---|---|---|---|
getSpecies(page) | page?: number | Observable<Species[]> | Return list of species as Observable |
getSpeciesById(id) | id: number | Observable< Species > | Returns species by id |
searchSpecies(name) | name: string | Observable<Species[]> | Search species by name |
Planets
Method | Parameters | Return | Description |
---|---|---|---|
getPlanets(page) | page?: number | Observable<Planet[]> | Return list of planets as Observable |
getPlanet(id) | id: number | Observable< Planet > | Returns planet by id |
searchPlanets(name) | name: string | Observable<Planet[]> | Search planets by name |
Using Angular2SwapiService
Get list of films and display data:
;;;
Search films by title:
;;;
Get film by id:
;;;
You can use the same pattern to get all the other resources from Star Wars API and display them in your application.
Where is Wookiee?
I don't speak wookie, do you? Still working on it.
StarWars API Resources
Please check full Star Wars API documentation by Paul Hallet at https://swapi.co/documentation