Skip to content

Instantly share code, notes, and snippets.

@MosesEsan
Last active April 8, 2021 16:49
Show Gist options
  • Save MosesEsan/7c9e68e2f1ce0be45399a192b016d178 to your computer and use it in GitHub Desktop.
Save MosesEsan/7c9e68e2f1ce0be45399a192b016d178 to your computer and use it in GitHub Desktop.
Trade Journal App Service
import axios from 'axios';
//API End Point
export const TRADE = `/api/trade`;
//INDEX
export async function getTrades(){
try{
let res = await axios.get(`${TRADE}`);
return res.data;
}catch (e) {
throw handler(e)
}
}
//CREATE AND EDIT
export async function createUpdateTrade(data, id){
try{
const options = {
method: !id ? 'POST' : 'PUT',
headers: {Accept: "application/json",},
data: data,
url : id ? `${TRADE}/${id}` : `${TRADE}`
};
let res = await axios(options);
return res.data;
}catch (err) {
throw err;
}
}
//READ
export async function getTrade(id){
try{
let res = await axios.get(`${TRADE}/${id}`);
return res.data;
}catch (err) {
throw err;
}
}
//DELETE
export async function deleteTrade(id) {
try {
let res = await axios.delete(`${TRADE}/${id}`);
return res.data;
}catch (err) {
throw err;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment