Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wikibase-rest-api-ts

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wikibase-rest-api-ts

Typescript model and API code for interacting with the REST API of a Wikibase instance (like Wikidata)

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-50%
Maintainers
0
Weekly downloads
 
Created
Source

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:

  • AliasesApi
  • DescriptionsApi
  • ItemsApi
  • LabelsApi
  • PropertiesApi
  • SitelinksApi
  • StatementsApi

Example

Suppose you want to get the label of Wikidata item Q1 in english. From the OpenAPI specification you find out that the appropriate method is GET /entities/items/{item_id}/labels/{language_code}, under the tag labels (=> LabelsApi). You don't need to specify which instance to use because Wikidata is the default.

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}`)
    );
Custom instance

If instead of Wikidata you want to use another Wikibase instance you need to pass its REST API base URL while initializing the API:

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(
        desc => console.log(`English description for Q1 is ${desc}`)
    );
Authentication and write operations

If you need to upload changes to the data you will need first to create an OAuth access token following the instructions at this link. Then you will need to pass the Authorization header for each call:

import { Configuration, DescriptionsApi } from "wikibase-rest-api-ts";
const api = new DescriptionsApi(new Configuration({
        headers: { Authorization: "Bearer " + YOUR_TOKEN }
    }));
api.replaceItemDescription({
        itemId: "Qxxx",
        languageCode: "en",
        replaceItemDescriptionRequest: {
            description: "New description of the item",
            comment: "Comment of your edit"
        }
    });

Further info

For further info and to contribute, see CONTRIBUTING.md.

Keywords

FAQs

Package last updated on 22 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc