Skip to content

JavaScript SDK

The official @datacommonsorg/client library wraps the REST API with a typed client. Point it at the Brasil Data Commons base URL instead of the default datacommons.org.

Terminal window
npm install @datacommonsorg/client

The one thing that differs from the upstream docs: set apiRoot to this instance.

import { DataCommonsClient } from "@datacommonsorg/client";
const client = new DataCommonsClient({
apiRoot: "https://brazildatacommons.com.br/core/api",
});
const rows = await client.getObservationsPoint({
variables: ["Count_Person"],
entities: ["country/BRA"],
date: "LATEST",
});
console.log(rows);

To fetch every state at once, use the relation-expression form:

const rows = await client.getObservationsPointWithin({
parentEntity: "country/BRA",
childType: "State",
variables: ["Count_Person"],
date: "LATEST",
});