1.0.0 • Published 1 year ago

@salesduck/iiko-cloud-api v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

iiko-cloud-api

The library describes the available methods, request and response bodies, which allows you to make your own rest client based on it

All types were generated automatically based on the iiko open api schema using generator

Setup

Add package to your typescript package

yarn add @salesduck/iiko-cloud-api

Usage

With openapi-fetch

import createClient from "openapi-fetch";

import { paths } from "@salesduck/iiko-cloud-api";

const { get, post, put, patch, del } = createClient<paths>({
  baseUrl: "https://myserver.com/api/v1/",
  headers: {
    Authorization: `Bearer token`,
  },
});

Directly

  1. Import schemas and paths
import { paths, schemas } from "@salesduck/iiko-cloud-api";
  1. Define alias for types
 export type getRegionsIikoParameters = paths["/api/1/regions"]["post"]["parameters"];

export type getRegionsIikoBody = schemas["iikoTransport.PublicApi.Contracts.Address.RegionsRequest"];

export type getRegionsIikoResponse = schemas["iikoTransport.PublicApi.Contracts.Address.RegionsResponse"];
  1. Use types in your code
const getRegionsIiko = async (
  parameters: getRegionsIikoParameters,
  data: getRegionsIikoBody
): Promise<getRegionsIikoResponse> => {
 // ... your code
};

Run your code with type safety

getRegionsIiko({ header: { Authorization: "token" } }, { organizationIds: [] })
  .then((response) => {
    console.log(response.regions);
    console.log(response.correlationId);
  })
  .catch(console.error);
1.0.0

1 year ago

0.0.1

1 year ago