GenericRestAPI adapter
The GenericRestAPI adapter is a flexible, configurable adapter that can connect to any REST API following common patterns. It's designed to reduce code duplication and provide a foundation for creating adapters for new systems without having to build them from scratch.
This adapter can be used in two ways:
- As a standalone adapter for systems that have a REST API
- As a base for building more specialized adapters (like LibreNMS, Observium, PeeringDB)
Key features
- Flexible authentication methods (token, API key, basic auth)
- Configurable endpoints and URL structures
- Response format handling with customizable extraction
- Transformation and filtering capabilities
- Environment variable support for credentials
Sync directions supported
- GenericRestAPI → Infrahub
Currently, the GenericRestAPI adapter supports only one-way synchronization from a REST API source to Infrahub. Syncing data back to the source is not yet supported and need to be done on custom adapters. Those adapters can use the generic one as base similar to what is done with Peering Manager adapter.
Configuration
Basic configuration
To use the GenericRestAPI adapter, specify genericrestapi as the name in your configuration:
source:
name: genericrestapi
settings:
url: "https://api.example.com"
api_endpoint: "/api/v1"
auth_method: "token"
token: "YOUR_API_TOKEN" # Better to use environment variables
Configuration parameters
| Parameter | Description | Default | Required |
|---|---|---|---|
url | Base URL of the API | None | Yes |
api_endpoint | API endpoint path | /api/v0 | No |
auth_method | Authentication method (token, x-auth-token, api-key, key, basic) | token | No |
| token | API token for token-based auth | None | For token auth |
| username | Username for basic auth | None | For basic auth |
| password | Password for basic auth | None | For basic auth |
verify_ssl | Whether to verify SSL certificates | true | No |
| timeout | Request timeout in seconds | 30 | No |
params | Additional query parameters to include in all requests | {} | No |
response_key_pattern | Pattern for extracting data from responses | None | No |
Environment variables
You can specify credentials using environment variables instead of storing them directly in the configuration:
| Setting | Environment Variables | Description |
|---|---|---|
url | URL, ADDRESS | API base URL |
| token | TOKEN | API token/key |
| username | USERNAME | Basic auth username |
| password | PASSWORD | Basic auth password |
The adapter will check for these environment variables in the order specified.