conpact fetch functionalities for react, react-native and nextjs with base url and custom header fuctinality
const data = await POST(/api/login, body)
Or
POST(/api/login, body)
.then(res=>{
console.log(res);
})
.catch(err=>{
console.log(err);
})
Or
const onError = (err) =>{ alert(err.message) } function onResonse(res){ //your setData with formate response setData(res) } POST(/api/login, body,{ onResonse, onError })
const data = await GET(/api/login)
import { fetchConfig } from '@upgradableweb/client'
fetchConfig.baseUrl = 'https://api.example.com'
fetchConfig.headers = { authorization: 'Bearer token' }
header asigning method { 'Content-Type': 'application/json', ...fetcher.headers, }
Package manager
Using npm$ npm install @upgradableweb/client
fetchConfig.cache | one of "default", "force-cache", "no-cache", etc
fetchConfig.next | for nextjs { revalidate: number, tags: [] }
fetchConfig.baseUrl = 'https://example.com'
await GET('https://api.example.com/login')
//reqest to https://api.example.com/login
fetchConfig.headers = { authorization: 'Bearer token1' }
await GET('https://api.example.com/login',{ authorization: 'Bearer token2'})
//Bearer token2 will be assigned
This software is licensed under the MIT License.