Package Exports
- wikibase-rest-api-ts
- wikibase-rest-api-ts/dist/index.js
- wikibase-rest-api-ts/dist/index.mjs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (wikibase-rest-api-ts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
wikibase-rest-api-ts
Typescript model and API code for interacting with the REST API of a Wikibase instance (like Wikidata).
Usage
Read the official OpenAPI specification for the Wikibase REST API at this link. Depending on the tags of the method you want to use, initialize an object of the relevant API class and call the appropriate method:
Example
Suppose you want to get the label of Wikidata item Q1 in english, from the OpenAPI specification you you find out that the appropriate method is /entities/items/{item_id}/labels, under the tag labels.
import { LabelsApi } from "wikibase-rest-api-ts";
const api = new LabelsApi();
api.getItemLabel({
itemId: "Q1", languageCode: "en"
}).then(
label => console.log(`English label for Q1 is ${label}`)
);Suppose instead you want to get the description for an entity on another Wikibase instance, you can use /entities/items/{item_id}/descriptions/{language_code} under the descriptions tag:
import { Configuration, DescriptionsApi } from "wikibase-rest-api-ts";
const api = new DescriptionsApi(new Configuration({
basePath: "https://url-to-my-wikibase-instance/w/rest.php/wikibase/v0",
}));
api.getItemDescription({
itemId: "Q1", languageCode: "en"
}).then(
label => console.log(`English description for Q1 is ${label}`)
);Further info
About this repository:
- openapi.json: Local OpenAPI definition of the API, cloned from the official one and adapted to work with OpenAPI generator (all structures that are referenced through
~1or/allOf/are extracted inside#/components/schemas/and referenced directly) - src/generated: Typescript API code, autogenerated with OpenAPI-generator from the above specification through
npm run generate- At the time of writing this, OpenAPI generator introduces a bug in the generated code solvable with
npm run fix
- At the time of writing this, OpenAPI generator introduces a bug in the generated code solvable with
- src/test includes some manually written tests for the code, runnable through
npm test - tsup.config.ts includes the configuration to transpile the autogenerated Typescript code into the packaged Javascript files in the dist folder with
npm run build - The autogenerated and output code can be cleaned up with
npm run clean
About the Wikibase REST API: