@upgradableweb/client

1.2.0 • Public • Published

@upgradableweb/client

conpact fetch functionalities for react, react-native and nextjs with base url and custom header fuctinality

Supported methods GET, POST, PUT, PATCH, DELETE

Example and reference for how to use

POST

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 })

GET

const data = await GET(/api/login)

Use same method FOR All http methods

Setting BASEURL & Headers

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

Other passing options

fetchConfig.cache | one of "default", "force-cache", "no-cache", etc fetchConfig.next | for nextjs { revalidate: number, tags: [] }

Default beavior

1. if url starts with http then baseUrl not taken as url

fetchConfig.baseUrl = 'https://example.com' await GET('https://api.example.com/login') //reqest to https://api.example.com/login

2. if you set authorization while fetching time then default is overight

fetchConfig.headers = { authorization: 'Bearer token1' } await GET('https://api.example.com/login',{ authorization: 'Bearer token2'}) //Bearer token2 will be assigned

License

This software is licensed under the MIT License.

Package Sidebar

Install

npm i @upgradableweb/client

Weekly Downloads

6

Version

1.2.0

License

MIT

Unpacked Size

8.14 kB

Total Files

4

Last publish

Collaborators

  • upgradableweb