-
-
Save dvallin/f5a1dddae6ac2951c13cf3944309c8a8 to your computer and use it in GitHub Desktop.
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, {AxiosPromise} from 'axios'; | |
import {Task} from "../domain/Task"; | |
const config = { | |
baseURL: 'http://localhost:4242' | |
}; | |
function unwrapAxiosResponse<T>(request: AxiosPromise<T>): Promise<T> { | |
return new Promise<T>((resolve, reject) => { | |
request | |
.then(response => resolve(response.data)) | |
.catch(error => { | |
reject(error) | |
}) | |
}); | |
} | |
export function fetchTasks(): Promise<Array<Task>> { | |
return unwrapAxiosResponse(axios.get<Array<Task>>('/api/tasks', config)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment