🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

@hastom/fetch

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hastom/fetch

Light wrapper around Fetch API

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

A little sugar to Fetch API

Axios-like request methods:

import { fetcher } from '@hastom/fetch'

await fetcher.get('https://google.com')

Auto-stringify get-params:

import { fetcher } from '@hastom/fetch'

await fetcher('https://google.com', {
  params: {
    query: 'string',
    and: ['also', 'arrays']
  }
})

Auto-strigify body to json and set content-type to application/json:

import { fetcher } from '@hastom/fetch'

await fetcher.post('https://google.com', {
  body: {
    query: 'string',
    and: ['also', 'arrays']
  }
})

Create instances with default params:

import { createFetchInstance } from '@hastom/fetch'

const authorizedFetch = createFetchInstance({
  headers: {
    Authorization: 'Bearer ...',
  },
})

await authorizedFetch.get('https://my-api.com/private-data')

and set base url:

import { createFetchInstance } from '@hastom/fetch'

const myApi = createFetchInstance({
  baseURL: 'https://my-api.com',
})

await myApi.get('/important-data')

Keywords

axios

FAQs

Package last updated on 10 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts