Created
March 18, 2019 16:11
-
-
Save Markonis/81d5ea673790d745b0de826c1cfbd3ab 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
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