readable-http-client
TypeScript icon, indicating that this package has built-in type declarations

0.0.8 • Public • Published

readable-http-client

Declarative http client for use against unpredictable http servers.

Installation

bun add readable-http-client

Example

I recommend you to use typia

import { fetch, handlers } from 'readable-http-client'
import typia, { type tags } from 'typia'

// In case no handlers matches the response, UnhandledResponseError is thrown
// who contains the request and response.

const ipAddress: string = await fetch({
    request: {
        url: 'https://ip.oxylabs.io/location',
        method: 'GET'
    },
    handlers: [
        handlers.is({
            headers: typia.createValidate<{
                ":code": 200,
                data: {
                    "content-type": "application/json"
                }
            }>(),
            body: typia.json.createIsParse<{
                ip: string & (tags.Format<'ipv4'> | tags.Format<'ipv6'>)
            }>(),
            handle(resp) {
                return resp.body.ip
            }
        })
    ]
})

console.info("My public IP address is:", ipAddress)

Appendix

This project was created using bun init in bun v1.2.8. Bun is a fast all-in-one JavaScript runtime.

Package Sidebar

Install

npm i readable-http-client

Weekly Downloads

1

Version

0.0.8

License

MIT

Unpacked Size

8.24 kB

Total Files

9

Last publish

Collaborators

  • spabot