Skip to content

Instantly share code, notes, and snippets.

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