Socket
Book a DemoInstallSign in
Socket

ceek

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ceek

0.1.1
latest
npmnpm
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

ceek

Ceek is an explicit request library for browser.

  • Won't transform data without explicit config.
  • Won't suppress expection silently (JSON parse error, config error, eg.).
  • Explicitly error handling.
  • Supports typescript for response data.
  • Supports upload progress.

Usage

import { ceek } from 'ceek'

const { json } = await ceek.post('https://example.com', {
  json: { foo: 'bar' }
})

API

ceek(options: CeekRequestOptions): CeekResponse

CeekRequestOptions

type CeekRequestOptions = {
  method:
    | 'get'
    | 'GET'
    | 'post'
    | 'POST'
    | 'put'
    | 'PUT'
    | 'patch'
    | 'PATCH'
    | 'head'
    | 'delete'
  url: string
  timeout?: number
  withCredentials?: boolean
  headers?: Record<string, string>
  responseType?: 'arraybuffer' | 'blob' | 'text'
  body?: XMLHttpRequestBodyInit
  json?: any
  query?: Record<string, string>
  baseUrl?: string
  onUploadProgress?: (
    progressEvent: ProgressEvent<XMLHttpRequestEventTarget>
  ) => void
  onDownloadProgress?: (
    progressEvent: ProgressEvent<XMLHttpRequestEventTarget>
  ) => void
}

CeekResponse

export type CeekResponse<T = any> = {
  status: number
  statusText: string
  headers: Record<string, string>
  body: string | ArrayBuffer | Blob
  json: T
}

Error handling

import { catchError, matchError, CEEK_ERROR } from 'ceek'

// promise style
ceek
  .get('https://example.com')
  .then((resp) => {
    console.log(resp.json)
  })
  .catch(catchError(({ ceekError, error }) => {
    if (ceekError) {
      switch ceekError.type {
        CEEK_ERROR.INVALID_JSON:
          console.log('json parse error')
          break
        default:
          console.log('some error')
      }
    }
  }))

// async style
try {
  const { json } = await ceek.get('https://example.com')
} catch (e) {
  matchError(e, ({ ceekError, error }) => {
    // ...
  })
}

TODO global error handler

import type { CeekError } from 'ceek'

const request = ceek.extend({
  onError(error: CeekError) {
    switch error.type {
      // ...
    }
  }
})

FAQs

Package last updated on 01 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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.