Skip to content

REST API Configuration

The Uplinkr API package is configured from the Laravel application that installs it.

That means:

  • the relevant .env file is the application’s .env
  • the relevant config file is config/uplinkr-api.php inside the Laravel app
  • the package does not read a separate .env file from inside vendor/

scherhak/uplinkr-api ships with a package config file that is merged into the Laravel application’s configuration.

The defaults come from the package itself, but in normal usage you configure the API through the host application:

Terminal window
.env
config/uplinkr-api.php

This is standard Laravel package behavior.

If you change environment values, clear Laravel’s config cache afterwards:

Terminal window
php artisan optimize:clear

If you want to customize the API configuration explicitly, publish the package config into your Laravel app:

Terminal window
php artisan vendor:publish --tag=uplinkr-api-config

This creates:

config/uplinkr-api.php

After publishing, you can adjust the values there or keep using .env variables referenced by that file.


If you add values to a .env file inside the package or under vendor/scherhak/uplinkr-api, Laravel will not use them for your application runtime.

Use the Laravel application’s root .env instead.

Correct location:

Terminal window
/your-laravel-app/.env

Not used at runtime:

Terminal window
/your-laravel-app/vendor/scherhak/uplinkr-api/.env

The package reads the following environment variables from the Laravel app:

Terminal window
UPLINKR_API_ROUTE_PREFIX=api/v1
UPLINKR_API_AUTH_ENABLED=true
UPLINKR_API_AUTH_HEADER=X-Uplinkr-Api-Key
UPLINKR_API_KEYS=replace-me-with-a-long-random-key
UPLINKR_API_ACCEPT_BEARER_TOKEN=false
UPLINKR_API_RATE_LIMIT_ENABLED=true
UPLINKR_API_RATE_LIMIT_KEY=uplinkr-api
UPLINKR_API_RATE_LIMIT_MAX_ATTEMPTS=60
UPLINKR_API_RATE_LIMIT_DECAY_MINUTES=1
UPLINKR_API_RATE_LIMIT_BY_IP=true

'route' => [
'prefix' => env('UPLINKR_API_ROUTE_PREFIX', 'api/v1'),
'middleware' => ['api'],
],

Defines the base URL prefix for all API routes.

Default:

/api/v1
'api_key' => [
'enabled' => (bool) env('UPLINKR_API_AUTH_ENABLED', true),
'header' => env('UPLINKR_API_AUTH_HEADER', 'X-Uplinkr-Api-Key'),
'accept_bearer_token' => (bool) env('UPLINKR_API_ACCEPT_BEARER_TOKEN', true),
'keys' => array_values(array_filter(array_map(
static fn (string $value): string => trim($value),
explode(',', (string) env('UPLINKR_API_KEYS', '')),
))),
],

This controls whether the API is protected by keys, which header is used, whether Bearer tokens are accepted, and which keys are valid.

Example:

Terminal window
UPLINKR_API_AUTH_ENABLED=true
UPLINKR_API_AUTH_HEADER=X-Uplinkr-Api-Key
UPLINKR_API_KEYS=key-one,key-two
UPLINKR_API_ACCEPT_BEARER_TOKEN=true
'rate_limit' => [
'enabled' => (bool) env('UPLINKR_API_RATE_LIMIT_ENABLED', true),
'key' => env('UPLINKR_API_RATE_LIMIT_KEY', 'uplinkr-api'),
'max_attempts' => (int) env('UPLINKR_API_RATE_LIMIT_MAX_ATTEMPTS', 60),
'decay_minutes' => (int) env('UPLINKR_API_RATE_LIMIT_DECAY_MINUTES', 1),
'by_ip' => (bool) env('UPLINKR_API_RATE_LIMIT_BY_IP', true),
],

These settings control the Laravel rate limiter used for the package routes.


  1. Install the package with Composer.
  2. Optionally publish the config file.
  3. Add the required UPLINKR_API_* values to the Laravel application’s .env.
  4. Clear the config cache.
  5. Call the API routes from your client or internal tooling.

Example:

Terminal window
composer require scherhak/uplinkr-api
php artisan vendor:publish --tag=uplinkr-api-config
php artisan optimize:clear

Example .env in the Laravel application:

Terminal window
UPLINKR_API_ROUTE_PREFIX=api/v1
UPLINKR_API_AUTH_ENABLED=true
UPLINKR_API_AUTH_HEADER=X-Uplinkr-Api-Key
UPLINKR_API_KEYS=replace-me-with-a-long-random-key
UPLINKR_API_ACCEPT_BEARER_TOKEN=false
UPLINKR_API_RATE_LIMIT_ENABLED=true
UPLINKR_API_RATE_LIMIT_MAX_ATTEMPTS=60
UPLINKR_API_RATE_LIMIT_DECAY_MINUTES=1

This results in:

  • routes under /api/v1
  • API key protection enabled
  • the custom header X-Uplinkr-Api-Key
  • rate limiting enabled for the REST API

The package is not configured from its own package directory. It is configured the Laravel way:

  • through the host app’s .env
  • through the host app’s config/uplinkr-api.php
  • with optional config publishing via vendor:publish