@gokarla-io/client
v0.0.1
Published
Karla API Client
Downloads
2
Readme
Karla TypeScript client
This TypeScript client library provides a comprehensive and easy-to-use interface to Karla's APIs and other services. Designed to help developers integrate and interact with Karla efficiently, this client supports all major service features including merchant, campaign, voucher, order and shipment management, data retrieval, and real-time updates.
Features
- Authentication: Handle API authentication seamlessly.
- Data Retrieval: Fetch data using simple asynchronous methods.
- Webhooks: Set up and manage webhooks.
- Error Handling: Robust error handling tailored for clarity and quick debugging.
- Type Safety: Full TypeScript support ensures type safety across all interactions.
Installation
Install the package via npm:
npm install @gokarla-io/client
Or using Yarn:
yarn add @gokarla-io/client
Usage
Here's a quick example to get you started with the Karla TypeScript client.
This example demonstrates how to authenticate and fetch merchant data:
Importing and Initializing the Client
import { Karla } from "@gokarla-io/client";
import type { KarlaREST } from "@gokarla-io/client";
const { rest: apiClient } = Karla({
auth: {
username: process.env.KARLA_API_USERNAME,
apiKey: process.env.KARLA_API_TOKEN,
},
});
The REST interface is exposed under the rest
attribute. More interfaces will be available in the future.
Fetching Merchant data
const { data } = await apiClient.GET("/v1/merchants", {
params: { query: { page: 1, per_page: 100 } },
});
Configuration Options
This client library offers various configuration options to tailor the API client to your needs:
- baseUrl: Override the default API endpoint for testing or development purposes.
- headers: Customize headers sent with each request.
Example of setting configuration options:
const karla = Karla({
baseUrl: process.env.KARLA_API_URL,
headers: {
"Custom-Header": "value",
},
});