Skip to content

Instantly share code, notes, and snippets.

@daniele-zurico
Created June 17, 2018 19:17
Show Gist options
  • Select an option

  • Save daniele-zurico/3c32bcd762d0d4d889b6e1ee284568d1 to your computer and use it in GitHub Desktop.

Select an option

Save daniele-zurico/3c32bcd762d0d4d889b6e1ee284568d1 to your computer and use it in GitHub Desktop.
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