Created
June 17, 2018 19:17
-
-
Save daniele-zurico/3c32bcd762d0d4d889b6e1ee284568d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class SwapiService { | |
| private readonly baseUrl = 'https://swapi.co/api/'; | |
| constructor(private http: HttpClient) {} | |
| getHeroes(page?: number): Observable<HeroesResponse> { | |
| const options = { | |
| params: {}, | |
| }; | |
| const link = `${this.baseUrl}people/`; | |
| if (page) { | |
| options.params = { page }; | |
| } | |
| return this.http.get<HeroesResponse>(link, options); | |
| } | |
| searchForHero(lookup: string): Observable<HeroesResponse> { | |
| const link = `${this.baseUrl}people/`; | |
| const options = { | |
| params: { | |
| search: lookup, | |
| }, | |
| }; | |
| return this.http.get<HeroesResponse>(link, options); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment