@amanooo/fetch
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

Custom fetch

npm (scoped)

Test

node test-server.js
node test.js

result:

const fetch = require('./index.js').default


async function get () {
    fetch.debug = false
    const res = await fetch.get('http://localhost:8000')
    console.log('get  ', res);
}
async function cookie () {
    fetch.debug = false
    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 main () {
    get()
    post()
    postWithAuth()
    cookie()
}

main()

Compile

npx tsc -d --outDir ./

Publish

npm publish --access public

Readme

Keywords

Package Sidebar

Install

npm i @amanooo/fetch

Weekly Downloads

2

Version

1.0.4

License

ISC

Unpacked Size

37 kB

Total Files

13

Last publish

Collaborators

  • amanooo