1.0.7 • Published 6 months ago

cardano-koios-client v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

TypeScript Client for XRAY/Graph Koios Tiny and Koios.REST API

Automatically generated Openapi-fetch (Axios) client for Koios Cardano RESTful API based on schema.yaml OpenAPI schema. Works great with XRAY/Graph Koios Tiny and the original Koios

Installation

To install the client with Yarn, run:

yarn install cardano-koios-client

To install the client with NPM, run:

npm i cardano-koios-client

Usage

import KoiosClient from "cardano-koios-client"

const client = KoiosClient("https://api.koios.rest/api/v1")

const app = async () => {
  const tip = await client.GET("/tip")

  if (tip.data) {
    console.log(tip.data?.[0]?.block_no)
  }
  if (tip.error) {
    console.error(tip.error)
  }
}

app()

Advanced Usage

const baseUrl = "https://api.koios.rest/api/v1" const headers = {} // rest headers const client = KoiosClient(baseUrl, headers)

const app = async () => { const blocks = await client.GET("/blocks", { headers: { "Content-Type": "application/json" }, // one shot headers params: { query: { limit: 1, offset: 100, epoch_no: "eq.250", }, }, })

console.log(blocks.data) }

app()

</details>

<details>
<summary>Request Cancellation (AbortSignal)</summary>

```TypeScript
import KoiosClient from "cardano-koios-client"

const client = KoiosClient("https://api.koios.rest/api/v1")

const app = async () => {
  const abortController = new AbortController()

  setTimeout(() => {
    abortController.abort() // cancel request
    console.log('Aborted!')
  }, 200)

  const tip = await client.GET("/tip", {
    signal: abortController.signl,
  })

  if (tip.data) {
    console.log(tip.data?.[0]?.block_no)
  }
  if (tip.error) {
    console.error(tip.error)
  }
}

app()

Endpoints

API URLs

Managed by Cardano Community (Koios Elastic Query Layer, HAproxy Balancer)

https://api.koios.rest/api/v1
https://preprod.koios.rest/api/v1
https://preview.koios.rest/api/v1
https://guild.koios.rest/api/v1

Managed by XRAY/Network (XRAY/Graph, Cloudflare WAF & Load Balancer)

https://graph.xray.app/output/koios/mainnet/api/v1
https://graph.xray.app/output/koios/preprod/api/v1
https://graph.xray.app/output/koios/preview/api/v1
1.0.7

6 months ago

1.0.6

9 months ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago