Skip to content

Instantly share code, notes, and snippets.

@dvallin
Created November 29, 2017 16:46
Show Gist options
  • Save dvallin/f5a1dddae6ac2951c13cf3944309c8a8 to your computer and use it in GitHub Desktop.
Save dvallin/f5a1dddae6ac2951c13cf3944309c8a8 to your computer and use it in GitHub Desktop.
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