UNPKG

@amanooo/fetch

Version:
49 lines (44 loc) 1.25 kB
const fetch = require('./index.js').default async function get () { // fetch.debug = true const res = await fetch.get('http://localhost:8000') console.log('get ', res); } async function cookie () { fetch.credentials = "same-origin" const headers = { 'content-type': 'application/json', cookie: 'accessToken=1234abc;userId=1234' } fetch.headers = headers const res = await fetch.get('http://localhost:8000/cookie') console.log('cookie ', res); } async function post () { const res = await fetch.post('http://localhost:8000') console.log('post ', res); } async function postWithAuth () { const headers = { 'content-type': 'application/json', Authorization: 'Basic YTpi' } fetch.headers = headers const res = await fetch.post('http://localhost:8000/auth') console.log('postWithAuth ', res); } async function random () { fetch.retryOpts = { } const res = await fetch.post('http://localhost:8000/random', undefined, undefined, {}) console.log('random ', res); } async function main () { get() post() postWithAuth() cookie() await random().catch(e => console.log('catch error')) console.log('finish'); } main()