https://github.com/apitoolkit/apitoolkit-slim
APItoolkit's Slim (PHP) client SDK.
https://github.com/apitoolkit/apitoolkit-slim
apitoolkit apitoolkit-sdk php slim-framework
Last synced: 3 months ago
JSON representation
APItoolkit's Slim (PHP) client SDK.
- Host: GitHub
- URL: https://github.com/apitoolkit/apitoolkit-slim
- Owner: apitoolkit
- Created: 2023-12-10T12:13:44.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-06T18:08:26.000Z (6 months ago)
- Last Synced: 2025-03-09T11:01:59.010Z (4 months ago)
- Topics: apitoolkit, apitoolkit-sdk, php, slim-framework
- Language: PHP
- Homepage: https://apitoolkit.io/docs/sdks/php/slim
- Size: 191 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

## Slim SDK
[](https://github.com/topics/apitoolkit-sdk) [](https://apitoolkit.io/discord?utm_campaign=devrel&utm_medium=github&utm_source=sdks_readme) [](https://apitoolkit.io/docs/sdks/php/slim?utm_campaign=devrel&utm_medium=github&utm_source=sdks_readme)
APItoolkit is an end-to-end API and web services management toolkit for engineers and customer support teams. To integrate your Slim (PHP) application with APItoolkit, you need to use this SDK to monitor incoming traffic, aggregate the requests, and then deliver them to the APItoolkit's servers.
---
## Table of Contents
- [Installation](#installation)
- [Open Telemetry Configuration](#setup-opentelemetry)
- [APItoolkit Middleware Setup](#setup-apitoolkit-middleware)
- [Contributing and Help](#contributing-and-help)
- [License](#license)---
## Installation
Kindly run the command below to install the apitoolkit-slim sdk and otel packages:
```sh
composer require \
open-telemetry/sdk \
open-telemetry/exporter-otlp \
open-telemetry/opentelemetry-auto-slim \
open-telemetry/opentelemetry-auto-psr18 \
apitoolkit/apitoolkit-slim```
## Setup Opentelemetry
#### Installing opentelemetry extension
After installing the necessary packages, you'll need to install the opentelemetry extention and add it to your `php.ini` file
```sh
pecl install opentelemetry
```Then add it to your `php.ini` file like so.
```ini
[opentelemetry]
extension=opentelemetry.so
```Export the following environment variables to configure the opentelemetry extension.
```sh
export OTEL_PHP_AUTOLOAD_ENABLED=true
export OTEL_SERVICE_NAME=your-service-name
export OTEL_TRACES_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_ENDPOINT=http://otelcol.apitoolkit.io:4318
export OTEL_RESOURCE_ATTRIBUTES="at-project-key={ENTER_YOUR_API_KEY_HERE}"
export OTEL_PROPAGATORS=baggage,tracecontext
```## Setup APItoolkit Middleware
Next, create a new instance of the `APIToolkitMiddleware` class and register the middleware with the Slim Framework in the `app/middleware.php` file. This creates a customs spans which captures and sends http request info such as headers, requests and repsonse bodies, matched route etc. for each request
```php
use Slim\Factory\AppFactory;
use APIToolkit\APIToolkitMiddleware;require __DIR__ . '/vendor/autoload.php';
$app = AppFactory::create();
$apitoolkitMiddleware = new APIToolkitMiddleware(['captureRequestBody' => true]);
$app->add($apitoolkitMiddleware);
$app->get('/', function ($request, $response) {
$response->getBody()->write('Hello, World!');
return $response;
});$app->run();
```> [!NOTE]
>
> The `{ENTER_YOUR_API_KEY_HERE}` demo string should be replaced with the [API key](https://apitoolkit.io/docs/dashboard/settings-pages/api-keys?utm_campaign=devrel&utm_medium=github&utm_source=sdks_readme) generated from the APItoolkit dashboard.
> [!IMPORTANT]
>
> To learn more configuration options (redacting fields, error reporting, outgoing requests, etc.), please read this [SDK documentation](https://apitoolkit.io/docs/sdks/php/slim?utm_campaign=devrel&utm_medium=github&utm_source=sdks_readme).## Contributing and Help
To contribute to the development of this SDK or request help from the community and our team, kindly do any of the following:
- Read our [Contributors Guide](https://github.com/apitoolkit/.github/blob/main/CONTRIBUTING.md).
- Join our community [Discord Server](https://apitoolkit.io/discord?utm_campaign=devrel&utm_medium=github&utm_source=sdks_readme).
- Create a [new issue](https://github.com/apitoolkit/apitoolkit-slim/issues/new/choose) in this repository.## License
This repository is published under the [MIT](LICENSE) license.
---