Meal Tracker v1 - complete
This commit is contained in:
27
client/src/utils/api.js
Normal file
27
client/src/utils/api.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import axios from 'axios'
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: '/api',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
|
||||
export async function getEntries() {
|
||||
const { data } = await api.get('/entries')
|
||||
return data
|
||||
}
|
||||
|
||||
export async function createEntry(formData) {
|
||||
const { data } = await api.post('/entries', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
export async function deleteEntry(id) {
|
||||
await api.delete(`/entries/${id}`)
|
||||
}
|
||||
|
||||
export async function searchFoods(query) {
|
||||
const { data } = await api.get(`/foods/search?q=${encodeURIComponent(query)}`)
|
||||
return data
|
||||
}
|
||||
Reference in New Issue
Block a user