Skip to content

Commit d87a901

Browse files
authored
docs: update api package readme example (#6915)
1 parent 8cb08ff commit d87a901

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

packages/api/README.md

+8-15
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,23 @@
77

88
> This package is part of [ChainSafe's Lodestar](https://lodestar.chainsafe.io) project
99
10-
Typescript REST client for the [Ethereum Consensus API spec](https://github.com/ethereum/beacon-apis)
10+
Typescript REST client for the [Ethereum Consensus API](https://github.com/ethereum/beacon-apis)
1111

1212
## Usage
1313

14-
We use more typesafe approach for the API client, where all the errors are returned not thrown. This approach is more easy to document and better to handle all possible error cases.
14+
The REST client extends the native [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), it behaves very similar in terms of error and response handling. It returns the same [Response object](https://developer.mozilla.org/en-US/docs/Web/API/Response) with additional methods to simplify usage and it allows to override all [Request options](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) if needed.
1515

1616
```typescript
17-
import {getClient, HttpError} from "@lodestar/api";
17+
import {getClient} from "@lodestar/api";
1818
import {config} from "@lodestar/config/default";
1919

2020
const api = getClient({baseUrl: "http://localhost:9596"}, {config});
2121

22-
api.beacon
23-
.getStateValidator(
24-
"head",
25-
"0x933ad9491b62059dd065b560d256d8957a8c402cc6e8d8ee7290ae11e8f7329267a8811c397529dac52ae1342ba58c95"
26-
)
27-
.then((res) => {
28-
if (res.ok) {
29-
console.log("Your balance is:", res.response.data.balance, res.ok, res.status);
30-
} else {
31-
console.error(res.status, res.error.code, res.error.message);
32-
}
33-
});
22+
const res = await api.beacon.getStateValidator({stateId: "head", validatorId: 0});
23+
24+
const validator = res.value();
25+
26+
console.log("The validator balance is: ", validator.balance);
3427
```
3528

3629
## Prerequisites

packages/api/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lodestar/api",
3-
"description": "A Typescript implementation of the Ethereum Consensus light client",
3+
"description": "A Typescript REST client for the Ethereum Consensus API",
44
"license": "Apache-2.0",
55
"author": "ChainSafe Systems",
66
"homepage": "https://github.com/ChainSafe/lodestar#readme",

0 commit comments

Comments
 (0)