jaseci-web-client
v0.1.0
Published
A simple and customizable client for interacting with Jaseci's walker endpoints via HTTP requests. The client handles sending requests and managing authorization tokens with ease.
Downloads
74
Readme
Jaseci Web Client
A simple and customizable client for interacting with Jaseci's walker endpoints via HTTP requests. The client handles sending requests and managing authorization tokens with ease.
Installation
You can install the package using npm:
npm install jaseci-web-client
Or using Yarn:
yarn add jaseci-web-client
Usage
import { JaseciWebClient } from "jaseci-web-client";
const client = new JaseciWebClient({
baseUrl: "https://your-jaseci-server.com", // Required: The base URL of the Jaseci API.
token: "your-auth-token", // Optional: Your authentication token for the API.
timeout: 5000, // Optional: Timeout for requests in milliseconds (default is 10000).
});
client
.call("walker_name", {
payload: { key: "value" }, // Required: Payload to send with the walker request.
jid: "optional-jid", // Optional: Provide a job ID if needed.
authorize: true, // Optional: Defaults to true, pass false to skip authorization.
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
API
JaseciWebClient Constructor
Creates a new instance of the JaseciWebClient.
const client = new JaseciWebClient(options);
Options
Options
| Option | Type | Description | Required | | ------- | ------ | ------------------------------------------------------------------------------- | -------- | | baseUrl | string | The base URL of the Jaseci server (e.g., https://your-jaseci-server.com). | Yes | | timeout | number | Timeout for the HTTP requests, in milliseconds. Defaults to 10000 (10 seconds). | No | | token | string | Optional authentication token for authorized requests (usually a Bearer token). | No |
call
Method
Send a request to a specific walker.
client.call(walker_name, options);
Parameters
Parameters
| Parameter | Type | Description | Required | | ----------- | ----------- | ------------------------------------------------------------------------------ | -------- | | walker_name | string | The name of the walker to call (the endpoint will be /walker/{walker_name}). | Yes | | options | CallOptions | The options for the call, including payload, job ID, and authorization toggle. | Yes |
CallOptions
| Option | Type | Description | Required | | --------- | ------------------- | ------------------------------------------------------------------ | -------- | | payload | Record<string, any> | The payload (data) to send to the walker. | Yes | | jid | string | Optional job ID for the request. | No | | authorize | boolean | Whether to include authorization in the request. Defaults to true. | No |
setToken Method
Update or set the authorization token after the client is initialized.
client.setToken("new-token");
Response Format
The response for the call
method will always include a status
object and an array of reports. Example response format:
{
"status": 200,
"reports": [
{
"some_key": "some_value"
}
]
}
Example Response Handling
client
.call("walker_name", { payload: { key: "value" } })
.then((response) => {
console.log("Status:", response.status);
console.log("Reports:", response.reports);
})
.catch((error) => {
console.error("Error:", error);
});
Customization and Extensibility
You can extend the client by adding additional request options like headers, interceptors, or specific API routes if needed.
Contributing
If you have any suggestions, ideas, or issues, feel free to open an issue or submit a pull request on GitHub.
License
This project is licensed under the MIT License.
Building the Library
Make sure you build the library before publishing so that everything is compiled into the dist/
folder:
npm run build