@egomobile/api-client
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

npm last build PRs Welcome

@egomobile/api-client

A generic REST client, designed for use in Kubernetes environment e.g.

Install

Execute the following command from your project folder, where your package.json file is stored:

npm install --save @egomobile/api-client

Usage

import ApiClient from "@egomobile/api-client";

async function main() {
  const apiClient = new ApiClient({
    // do a client_credentials oAuth flow
    auth: {
      clientId: "my-client-id",
      clientSecret: "my-client-secret",
    },
    baseURL: "https://api.example.com/",
  });

  // do a GET request on https://api.example.com/my-service1/v1/foo
  const getResponse = await apiClient.withClient(async (client) => {
    return await client.get("/my-service1/v1/foo");
  });

  // do a POST request on https://api.example.com/my-service2/v2/bar
  const postResponse = await apiClient.withClient(async (client) => {
    return await client.post("/my-service2/v2/bar", {
      baz: 42,
    });
  });

  // do a DELETE request on https://api.example.com/my-service3/beta/baz-resource/42
  const deleteResponse = await apiClient.withClient(async (client) => {
    return await client.delete("/my-service3/beta/baz-resource/42");
  });
}

main().catch(console.error);

Documentation

The API documentation can be found here.

Package Sidebar

Install

npm i @egomobile/api-client

Weekly Downloads

1

Version

0.3.0

License

LGPL-3.0

Unpacked Size

32.2 kB

Total Files

12

Last publish

Collaborators

  • ekmobile
  • egodux
  • mkloubertego
  • mkloubert
  • ekegodigital