-
-
Save dvallin/1690fb542b5e383be41edafa19024dd1 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 from 'axios'; | |
import _ from 'lodash'; | |
import {Task} from "../domain/Task"; | |
const config = { | |
baseURL: 'http://localhost:4242' | |
}; | |
export async function fetchTasks(): Promise<Array<Task>> { | |
const { data } = await axios.get('/api/tasks', config); | |
return _.map(data, (task) => new Task(task.id, task.title)); | |
} | |
export async function addTask(title: string): Promise<Task> { | |
const { data } = await axios.post('/api/tasks', {title}, config); | |
return new Task(data.id, data.title); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment