Skip to content

Instantly share code, notes, and snippets.

@Markonis
Created March 18, 2019 16:11
Show Gist options
  • Save Markonis/81d5ea673790d745b0de826c1cfbd3ab to your computer and use it in GitHub Desktop.
Save Markonis/81d5ea673790d745b0de826c1cfbd3ab to your computer and use it in GitHub Desktop.
function sendRequest<TInput, TOutput>(
endpoint: ApiEndpoint<TInput, TOutput>,
data?: TInput) {
return request<TOutput>({
url: endpoint.pathStr(),
data: data,
method: 'POST'
});
}
export function loadAllRecipes() {
sendRequest(api.recipe.list)
.then((recipes) => { allRecipes = recipes; });
}
export function createRecipe(recipe: Recipe) {
sendRequest(api.recipe.create, recipe).then(loadAllRecipes);
}
export function destroyRecipe(recipe: Recipe) {
const params = { id: recipe.id };
sendRequest(api.recipe.destroy, params).then(loadAllRecipes);
}
export function getAllRecipes() {
return allRecipes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment