Setup fetchers

This commit is contained in:
goncy
2021-08-25 11:13:47 -03:00
parent b64b3f8360
commit 7bdefa3f48
2 changed files with 159 additions and 6 deletions

View File

@@ -1,7 +1,17 @@
import { Fetcher } from '@commerce/utils/types'
export const fetcher: Fetcher = async () => {
throw new Error(
'Client side fetching has not been implemented yet, try to fetch from server side.'
)
const clientFetcher: Fetcher = async ({ method, url, body }) => {
const response = await fetch(url!, {
method,
body: body ? JSON.stringify(body) : undefined,
headers: {
'Content-Type': 'application/json',
},
})
.then((response) => response.json())
.then((response) => response.data)
return response
}
export default clientFetcher