SDKs overview
ApicAgent offers Software Development Kits (SDKs) and client libraries designed to facilitate programmatic interaction with its API monitoring and testing services. These tools allow developers to integrate ApicAgent's capabilities directly into their applications, build custom automation scripts, or extend existing CI/CD pipelines. The primary goal of ApicAgent's SDKs is to simplify the process of defining, deploying, and managing API monitors without requiring direct interaction with the ApicAgent web interface for every configuration change. This approach supports automation for tasks such as creating new monitors for newly deployed endpoints, updating existing monitor configurations, or querying monitoring results programmatically.
The official SDKs generally encapsulate the underlying REST API calls, providing language-specific methods and data structures. This abstraction aims to reduce the boilerplate code required to interact with the API, handle authentication, and parse responses. For instance, an SDK might provide a method like create_monitor() that takes parameters for an endpoint URL, expected status code, and alert channels, abstracting the HTTP POST request to the /monitors endpoint. Community-contributed libraries may extend this functionality or provide wrappers for languages not officially supported, often focusing on specific use cases or frameworks.
Official SDKs by language
ApicAgent provides official SDKs for several popular programming languages, allowing developers to integrate API monitoring functionality directly into their applications and automation scripts. These SDKs are maintained by ApicAgent and aim to provide a stable and well-documented interface to the ApicAgent API. Each SDK typically includes methods for common operations such as creating, updating, deleting, and fetching API monitors, as well as managing alerts and retrieving performance data. The official documentation for the ApicAgent API provides detailed information on each endpoint and its parameters, which the SDKs then wrap for ease of use ApicAgent API documentation.
The following table outlines the officially supported SDKs, their respective package managers, and general maturity:
| Language | Package Name | Typical Install Command | Maturity |
|---|---|---|---|
| Python | apicagent-sdk-python |
pip install apicagent-sdk-python |
Stable |
| Node.js | @apicagent/sdk-node |
npm install @apicagent/sdk-node |
Stable |
| Go | github.com/apicagent/apicagent-sdk-go |
go get github.com/apicagent/apicagent-sdk-go |
Stable |
These SDKs are designed to abstract the complexities of making direct HTTP requests, handling authentication (typically via API keys), and parsing JSON responses. For instance, the Python SDK might offer object-oriented representations of monitors and alerts, allowing developers to manipulate these resources using Python classes and methods rather than constructing raw JSON payloads. Detailed usage examples and API references for each SDK are available through the ApicAgent developer documentation ApicAgent developer portal.
Installation
Installing ApicAgent SDKs typically involves using the standard package manager for the respective programming language. Each SDK is distributed through its language's official package repository, simplifying dependency management and updates. Before installation, developers should ensure they have the correct runtime environment and package manager installed.
Python SDK Installation
The Python SDK for ApicAgent is distributed via PyPI. To install it, use pip:
pip install apicagent-sdk-python
This command downloads the latest version of the apicagent-sdk-python package and its dependencies. It is generally recommended to install Python packages within a virtual environment to avoid conflicts with system-wide packages Python virtual environments documentation.
Node.js SDK Installation
The Node.js SDK is available on npm, the package manager for JavaScript. Use npm or yarn to add it to your project:
npm install @apicagent/sdk-node
# or
yarn add @apicagent/sdk-node
This command adds the @apicagent/sdk-node package to your node_modules directory and updates your package.json file. Node.js projects typically manage dependencies locally, and the SDK requires a Node.js runtime environment (version 12.x or higher is generally recommended).
Go SDK Installation
For Go projects, the SDK is installed using the go get command, which fetches the package from its GitHub repository:
go get github.com/apicagent/apicagent-sdk-go
This command downloads the Go package and its dependencies, making it available for import in your Go source files. Go modules are used for dependency management, ensuring consistent builds. After running go get, you will typically see the module listed in your go.mod file. Compiling a Go application with the SDK will embed the necessary code directly into the resulting binary.
Quickstart example
This quickstart example demonstrates how to use the ApicAgent Python SDK to create a new API monitor. The process involves initializing the client with an API key, defining the parameters for the new monitor, and then calling the appropriate method to create it. This example assumes you have your ApicAgent API key available, which can be generated from your ApicAgent account settings ApicAgent API key management guide.
Python Quickstart: Creating an Uptime Monitor
First, ensure you have the Python SDK installed as described in the installation section. Then, you can use the following Python code to create a simple uptime monitor that checks an external public API endpoint.
import os
from apicagent_sdk_python import ApicAgentClient
from apicagent_sdk_python.models import MonitorCreateRequest, MonitorType, AlertChannelType
# Retrieve API key from environment variable for security
API_KEY = os.getenv("APICAGENT_API_KEY")
if not API_KEY:
raise ValueError("APICAGENT_API_KEY environment variable not set.")
# Initialize the ApicAgent client
client = ApicAgentClient(api_key=API_KEY)
try:
# Define the new monitor's parameters
monitor_data = MonitorCreateRequest(
name="Public API Health Check",
url="https://jsonplaceholder.typicode.com/posts/1",
monitor_type=MonitorType.HTTP_GET,
interval_minutes=5, # Check every 5 minutes
expected_status_code=200,
timeout_seconds=10,
alert_channels=[
{"type": AlertChannelType.EMAIL, "value": "[email protected]"}
]
)
# Create the monitor
new_monitor = client.monitors.create_monitor(monitor_data)
print(f"Successfully created monitor: {new_monitor.name} (ID: {new_monitor.monitor_id})")
print(f"Monitor URL: {new_monitor.url}")
except Exception as e:
print(f"Error creating monitor: {e}")
This snippet performs the following actions:
- Imports necessary modules:
ApicAgentClientfor API interaction, and data models likeMonitorCreateRequest,MonitorType, andAlertChannelTypeto structure the request. - Loads API Key: Retrieves the ApicAgent API key from an environment variable (
APICAGENT_API_KEY) for security best practices. - Initializes Client: Creates an instance of
ApicAgentClient, authenticating with the provided API key. - Defines Monitor Request: Constructs a
MonitorCreateRequestobject with details such as the monitor's name, target URL, HTTP method (HTTP_GET), check interval, expected HTTP status code, and a timeout. An email alert channel is also specified. - Creates Monitor: Calls the
create_monitormethod on the client'smonitorsservice, passing the defined monitor data. - Prints Confirmation: If successful, it prints the name and ID of the newly created monitor.
Before running this code, ensure you set the APICAGENT_API_KEY environment variable with your actual ApicAgent API key. This quickstart demonstrates a basic monitor creation; the SDKs support more complex configurations, including custom headers, body payloads for POST requests, and various validation rules.
Community libraries
While ApicAgent provides official SDKs for core languages, the developer community often contributes additional libraries, tools, and integrations. These community-driven projects can extend ApicAgent's functionality in several ways:
- Wrappers for other languages: Developers may create wrappers for languages not officially supported by ApicAgent, allowing a broader range of applications to interact with the platform.
- Framework-specific integrations: Libraries might be developed to integrate ApicAgent monitoring directly into specific web frameworks (e.g., Django, Ruby on Rails, Spring Boot) or serverless platforms (e.g., AWS Lambda, Google Cloud Functions), streamlining the setup process within those environments.
- CLI tools: Command-line interface (CLI) tools built by the community can offer alternative ways to manage ApicAgent resources, potentially providing more scriptable or interactive experiences than the official SDKs for certain tasks.
- Automation scripts: Generic scripts or templates for common automation workflows (e.g., deploying monitors as part of a CI/CD pipeline, generating reports) can be shared within the community.
- Custom alert integrations: While ApicAgent supports various alert channels, community contributions might include integrations with niche communication platforms or custom notification systems.
ApicAgent encourages community contributions and often highlights notable projects in its documentation or on its developer forum. When using community-contdeveloped libraries, it is important to review their documentation, licensing, and maintenance status, as they may not carry the same support guarantees as official SDKs. Developers can typically find these resources by searching relevant package repositories (like PyPI, npm, or GitHub) for apicagent or related keywords. Direct links to community projects are generally maintained on the ApicAgent developer forum or community section of their official website, providing a central place for discovery ApicAgent community resources.
For example, a community library might provide a Terraform provider for ApicAgent, allowing infrastructure-as-code practitioners to define and manage ApicAgent monitors alongside their other cloud resources using declarative configuration. This approach aligns with modern DevOps practices by treating monitoring configurations as version-controlled code, similar to how infrastructure is managed. Another common community contribution could be a Grafana data source plugin, enabling users to visualize ApicAgent monitoring data directly within their existing Grafana dashboards, consolidating observability efforts.