Skip to content

Deps-Tech/deps-js

Repository files navigation

@depsapi/deps-js

Isomorphic TypeScript client for the Deps API.

The @depsapi/deps-js package is a lightweight and powerful client for interacting with the Deps API in any JavaScript environment.

Features

  • Isomorphic: Works seamlessly in Node.js, Deno, and modern browsers.
  • Typed: Fully typed with TypeScript for a better developer experience.
  • Lightweight: Built with ofetch for a small bundle size.
  • Promise-based: Modern asynchronous API using Promises.
  • Modular: API methods are grouped into logical modules.

Usage

Node.js

Install with pnpm install @depsapi/deps-js. We recommend using Node.js v20 (LTS).

import { DepsClient } from "@depsapi/deps-js";
Browsers Load @depsapi/deps-js directly from esm.sh
<script type="module">
import { DepsClient } from "https://esm.sh/@depsapi/deps-js";
</script>
Deno Load @depsapi/deps-js directly from esm.sh
import { DepsClient } from "https://esm.sh/@depsapi/deps-js?dts";

DepsClient API Client

The DepsClient is the main entry point for interacting with the Deps API.

Example: Get the API status.

const client = new DepsClient({ apiKey: 'YOUR_API_KEY' });

const status = await client.status.get();
console.log(status);

Constructor options

name type description
apiKey string Your Deps API key. This is a required parameter.
baseUrl string The base URL of the Deps API. Defaults to https://api.depscian.tech.

API Modules

The client provides access to the API through a set of modules:

  • client.admins
  • client.families
  • client.fractions
  • client.ghetto
  • client.leadership
  • client.map
  • client.online
  • client.player
  • client.sobes
  • client.status

Example: Get the online players on a server.

const online = await client.online.get({ serverId: '1' });
console.log(online);

Error Handling

API errors are thrown as instances of DepsApiError or ValidationError.

import { DepsClient, DepsApiError, ValidationError } from '@depsapi/deps-js';

const client = new DepsClient({ apiKey: 'YOUR_API_KEY' });

try {
  const player = await client.player.find({ serverId: '1', nickname: 'NonExistentPlayer' });
} catch (error) {
  if (error instanceof ValidationError) {
    console.error('Validation Error:', error.data);
  } else if (error instanceof DepsApiError) {
    console.error('API Error:', error.message);
  } else {
    console.error('An unknown error occurred:', error);
  }
}

LICENSE

MIT

About

Isomorphic TypeScript client for the Deps API

Resources

License

Stars

Watchers

Forks