PHP code example of evrenonur / api-lens
1. Go to this page and download the library: Download evrenonur/api-lens library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
evrenonur / api-lens example snippets
// config/api-lens.php
return [
'enabled' => env('API_LENS_ENABLED', true),
'path' => 'api-lens',
'middleware' => ['web'],
'],
'auth' => [
'enabled' => false,
'middleware' => [],
],
'features' => [
'live_testing' => true,
'code_snippets' => true,
'openapi_export' => true,
'debug_metrics' => true,
'example_generation' => true,
],
'code_snippets' => [
'languages' => ['curl', 'javascript', 'python', 'php', 'axios', 'fetch', 'guzzle', 'http'],
],
'cache' => [
'enabled' => false,
'ttl' => 3600,
],
];
/**
* @api-lens-group Users
*/
class UserController extends Controller
{
/**
* List all users.
*
* Returns a paginated list of users with optional filtering.
*
* @api-lens-auth bearer
* @api-lens-tag admin
* @api-lens-response 200 {"data": [{"id": 1, "name": "John"}], "meta": {"total": 50}}
*/
public function index(Request $request)
{
// ...
}
/**
* Create a new user.
*
* @api-lens-response 201 {"data": {"id": 1, "name": "John"}, "message": "User created"}
*/
public function store(StoreUserRequest $request)
{
// ...
}
/**
* Delete user.
*
* @api-lens-deprecated 2025-06-01 Use PATCH /users/{user}/deactivate instead
*/
public function destroy(User $user)
{
// ...
}
}
'features' => [
'debug_metrics' => true,
],
// config/api-lens.php
'enabled' => env('API_LENS_ENABLED', false),
// Or add auth middleware
'auth' => [
'enabled' => true,
'middleware' => ['auth:sanctum', 'can:view-api-docs'],
],
bash
php artisan vendor:publish --tag=api-lens-config
bash
# Export as OpenAPI 3.1.0 JSON
php artisan api-lens:export docs/openapi.json --format=openapi
# Export as Postman Collection
php artisan api-lens:export docs/postman.json --format=postman
# Default export (api.json in project root)
php artisan api-lens:export
# Overwrite without confirmation
php artisan api-lens:export docs/openapi.json --format=openapi --force