@raddo/easy-fetch

    1.0.1 • Public • Published

    Human-friendly typed HTTP request library for Node.js or JS Client

    Install

    $ npm install easy-fetch
     or
    $ yarn add easy-fetch
    

    Usage

    - No gen. types and no parsing

    import fetch from "easy-fetch"
    
    const res = await fetch("https://api.chucknorris.io/jokes/random")
    
    console.log(res) // Normal fetch Response, res: Response | null

    - Callback with no gen. types

    import fetch from "easy-fetch"
    
    // const res: any | null
    const res = await fetch(
      "https://api.chucknorris.io/jokes/random",
      ({ parsedAPIResponse }) => parsedAPIResponse
    )
    console.log(res) // Parsed response ( body.json() )

    - Callback with gen. types

    import fetch from "easy-fetch"
    
    type APIResponse = {
      categories: any[]
      created_at: string
      icon_url: string
      id: string
      updated_at: string
      url: string
      value: string
    }
    
    const res = await fetch<string, APIResponse>(
      "https://api.chucknorris.io/jokes/random",
      // parsedAPIResponse: as APIResponse
      ({ parsedAPIResponse }) => parsedAPIResponse.value // ... fetch<string, ... >
    )
    console.log(res) // res: string | null
    
    // OR
    
    const res = await fetch<APIResponse, APIResponse>(
      "https://api.chucknorris.io/jokes/random",
      // parsedAPIResponse: as APIResponse
      ({ parsedAPIResponse }) => parsedAPIResponse // ... fetch<APIResponse, ... >
    )
    console.log(res) // res: APIResponse | null

    Maintainer

    Radovan Pelka (Rado)

    | Radovan Pelka

    Install

    npm i @raddo/easy-fetch

    DownloadsWeekly Downloads

    3

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    10.1 kB

    Total Files

    4

    Last publish

    Collaborators

    • raddo