Created
July 11, 2018 20:22
-
-
Save amrfarid140/b919ad523a7521509118ac62952652ce to your computer and use it in GitHub Desktop.
A service that uses Axios to fetch list of Facebook repositories
This file contains 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
import axios from "axios"; | |
import { Observable, Observer } from "rxjs"; | |
import { IRepositroy } from "./models/Repository"; | |
export class ApiService { | |
private readonly baseUrl = "https://api.github.com/"; | |
public getRepos(): Observable<IRepositroy[]> { | |
return Observable.create(async (observer: Observer<IRepositroy[]>) => { | |
try { | |
const response = await axios.get<IRepositroy[]>( | |
`${this.baseUrl}orgs/facebook/repos` | |
); | |
observer.next(response.data); | |
observer.complete(); | |
} catch (error) { | |
observer.error(error); | |
observer.complete(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment