Skip to content

metahkg/metahkg-api

Repository files navigation

Metahkg Api

Client for the metahkg server. Generated with the openapi spec using nswag.

Regenerate

yarn generate

Install

yarn add @metahkg/api

Usage

Function names are based on operationIds.
For example, if the operationId is commentCreate, you can use api.commentCreate.

For operationIds of requests see api docs.

import { Client } from "@metahkg/api";

const axios = Axios.create();

axios.interceptors.request.use((config) => {
    const token = localStorage.getItem("token");
    if (token && config.headers) config.headers.Authorization = `Bearer ${token}`;
    return config;
});

axios.interceptors.response.use((response) => {
    if (response.headers.token) localStorage.setItem("token", response.headers.token);
    return response;
});

const api = new Client("https://dev.metahkg.org/api", axios);

api
  .thread(1)
  .then(console.log)
  .catch(console.error);