New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@lancercomet/fetcher

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

@lancercomet/fetcher

Yet another fetcher.

latest
npmnpm
Version
1.1.2
Version published
Maintainers
1
Created
Source

Fetcher

Yet another fetcher.

Quick start

import { Fetcher } from '@lancercomet/fetcher'

const fetcher = new Fetcher()

const { data, error } = await fetcher.requestJSON({
  url: '/me',
  method: 'GET'
})

Abort a request

import { Fetcher } from '@lancercomet/fetcher'

const fetcher = new Fetcher()

const sendRequest = async () => {
  const { data, error } = await fetcher.requestJSON({
    url: '/me',
    method: 'GET'
  })
  // ...
}

const abortRequest = () => {
  fetcher.abort()
}

<button onClick={sendRequest}>Send</button>
<button onclick={abortRequest}>Abort</button>

Work with SunTori

@Serializable()
class User {
  @JsonProperty('name')
  readonly username: string = ''

  @JsonProperty('age')
  readonly age: number = 0
}

const fetcher = new Fetcher()
const { data } = await fetcher.requestJSON({
  url: '/me',
  method: 'GET',
  type: User
})

data instanceof User  // true
data.username         // string
data.age              // number

Request Binary

// ArrayBuffer.
const { data: buffer, error } = await fetcher.requestBinary({
  url: '/binary'
}, 'arraybuffer')

// Blob.
const { data: blob, error } = await fetcher.requestBinary({
  url: '/binary'
}, 'blob') 

Request the API

"The API" is a type of data structure which would be like:

{
  "data": ...,
  "code": 0,
  "message": "OK"
}
const { data, error, message, code, status } = await fetcher.requestAPI({
  ...
})

License

Apache-2.0

Keywords

Fetcher

FAQs

Package last updated on 25 Apr 2022

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