Treblle with Lumen
Requirements
Section titled “Requirements”- PHP 7.2+
- Lumen 7+
Dependencies
Section titled “Dependencies”Installation
Section titled “Installation”Install Treblle for Lumen via Composer by running the following command in your console:
composer require treblle/treblle-lumenGetting started
Section titled “Getting started”Installing Lumen packages is a lot more complicated than Laravel packages and requires a few manual steps. If you want a completely automated process please use Laravel.
Step 1: Publish config files
Section titled “Step 1: Publish config files”The first thing we need to do is publish the Treblle config file and make sure Lumen loads it. To do that we need to copy/paste the package config file like so:
mkdir -p configcp vendor/treblle/treblle-lumen/config/treblle.php config/treblle.phpNow we can have Lumen load the config file. We do that by adding a new line in bootstrap/app.php, under the Register Config Files section, like so:
$app->configure('treblle');Step 2: Register middleware
Section titled “Step 2: Register middleware”We need to register the Treblle middleware in Lumen. To do add a new line of code to bootstrap/app.php, under the Register Middleware section, like so:
$app->routeMiddleware([ 'treblle' => Treblle\Middlewares\TreblleMiddleware::class]);Step 3: Configure Treblle
Section titled “Step 3: Configure Treblle”You need an API key and Project ID for Treblle to work. You can get those by creating a free account on treblle.com and your first project. You’ll get the two keys which you need to add to your .env file like so:
TREBLLE_API_KEY=YOUR_API_KEYTREBLLE_PROJECT_ID=YOUR_PROJECT_IDEnable Treblle on your API
Section titled “Enable Treblle on your API”Now that we’ve installed the package we simply need to enable it. Open routes/web.php and assign the treblle middleware to your API routes like so:
$router->group(['prefix' => 'api', 'middleware' => 'treblle'], function () use ($router) { $router->get('users', ['uses' => 'UserController@index']); $router->post('users', ['uses' => 'TestController@store']);});You’re all set. Next time someone makes a request to your API you will see it in real-time on your Treblle dashboard alongside other features like: auto-generated documentation, error tracking, analytics and API quality scoring.
Configuration options
Section titled “Configuration options”You can configure Treblle using just .ENV variables:
TREBLLE_IGNORED_ENV=local,dev,testDefine which environments Treblle should not log at all. By default, Treblle will log all environments except local, dev and test. If you want to change that you can define your own ignored environments by using a comma separated list, or allow all environments by leaving the value empty.
Masked fields
Section titled “Masked fields”Treblle masks sensitive information from both the request and response data as well as the request headers data before it even leaves your server. The following parameters are automatically masked: password, pwd, secret, password_confirmation, cc, card_number, ccv, ssn, credit_score.
You can customize this list by editing the array configuration file.