Skip to content

Conversation

@aaroncox
Copy link
Member

The goal of this PR is to:

  • Make the APIClient in the Antelope library just a functional shell without any knowledge of the endpoints.
  • Require that applications choose a specific implementation of an APIClient for an API type.
  • Allow those implementations to be extended for chain-specific customization.

Looking at the commits, it's basically just deleting the API calls, types, and tests.

This code has moved to a generic APIClient implementation for leap named @wharfkit/apiclient-leap.

https://github.com/wharfkit/apiclient-leap/tree/master/src

It can be used exactly the same as how it functioned in @wharfkit/antelope, developers exclusively using the antelope library will now just need to include this new dependency and update their imports.

import {APIClient} from '@wharfkit/apiclient-leap'

const client = new APIClient({url: 'https://jungle4.greymass.com'})

const info = await client.v1.chain.get_info()

Some new syntax is also available as part of this change, where you can import specific named APIs:

import {ChainAPI} from '@wharfkit/apiclient-leap'

const client = new ChainAPI({url: 'https://jungle4.greymass.com'})

const info = await client.get_info()

As mentioned before, the point of this is to offer chain specific implementations, which you'll now be able to do with packages that extend the leap package. I created one for WAX and called it @wharfkit/apiclient-wax.

https://github.com/wharfkit/apiclient-wax/tree/master/src

It again can be used exactly in the same way, just required using the specific import and package.

import {ChainAPI} from '@wharfkit/apiclient-wax'

const client = new ChainAPI({url: 'https://jungle4.greymass.com'})

const info = await client.get_info()

What this new wax specific package does is overrides the get_account call:

https://github.com/wharfkit/apiclient-wax/blob/master/src/chain.ts

In order to return new types:

https://github.com/wharfkit/apiclient-wax/blob/master/src/types.ts

Otherwise anything not defined falls back to @wharfkit/apiclient-leap.

This pattern that I'm establishing is what I want to use for things like a "Robo" API client, or a "Hyperion" or "AtomicAssets" client - where we can define additional calls that returned typed data.

I'm not entirely happy with how this turned out. I'm considering rewriting the entire APIClient class to make it aware of what chain its accessing and also allowing "plugins" of some sort that'll override the response types for specific chains.

Definitely need some input here.

@aaroncox aaroncox changed the base branch from master to experimental August 28, 2023 19:35
@aaroncox aaroncox merged commit 9211b92 into experimental Aug 28, 2023
@aaroncox aaroncox mentioned this pull request Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants