title: Laravel description: Laravel guide for our application.

Overview

Welcome to the Laravel guide. Here, you'll find all the information you need to get started with integrating our APIs into your Laravel application.

Prerequisites

Before proceeding, ensure you have the following:

  • PHP and Composer installed
  • Basic knowledge of the Laravel framework
  • A code editor (e.g., VSCode)
  • An API key provided by our service

Setup Instructions

Since we provide API endpoints and keys for you to integrate into your Laravel project, the setup process is simple.

  1. Obtain Your API Key: Ensure you have your API key ready. This key will be used to authenticate your requests to our APIs.

  2. Install Laravel and Set Up Your Project: If you haven’t already set up a Laravel project, you can do so with the following commands:

    composer create-project --prefer-dist laravel/laravel your-project-name
    cd your-project-name
    
  3. Install HTTP Client: Laravel provides an HTTP client wrapper for Guzzle, which makes API requests straightforward. Ensure it's installed:

    composer require guzzlehttp/guzzle
    
  4. Configure Environment Variables: Add your API key to the .env file to securely store your credentials:

    API_KEY=your-api-key-here
    

    In your config/services.php file, you can set up a configuration for your API service:

    return [
        // Other services...
        'your_api_service' => [
            'base_uri' => env('API_BASE_URI', 'https://api.yourservice.com'),
            'key' => env('API_KEY'),
        ],
    ];
    
  5. Using the API in Laravel: You can now use Laravel's HTTP client to interact with your API. Here’s an example of how you might fetch data from an API endpoint:

    use Illuminate\Support\Facades\Http;
    
    Route::get('/fetch-data', function () {
        $response = Http::withHeaders([
            'Authorization' => 'Bearer ' . config('services.your_api_service.key'),
        ])->get(config('services.your_api_service.base_uri') . '/endpoint');
    
        if ($response->successful()) {
            return response()->json($response->json());
        } else {
            return response()->json(['error' => 'Failed to fetch data'], 500);
        }
    });
    
  6. Testing the API Integration: Start your Laravel development server and test the integration by visiting the corresponding route:

    php artisan serve
    

    You can now navigate to http://localhost:8000/fetch-data to see the API data fetched by your Laravel application.

Additional Information

For more details on how to use our APIs, please refer to our official documentation.


### Key Adjustments:
- **Laravel Setup**: Included steps to set up a Laravel project if not already done, using Composer.
- **Environment Configuration**: Guided users on how to securely store and configure the API key using Laravel’s `.env` file and `config/services.php`.
- **API Integration Example**: Provided an example of how to use Laravel’s HTTP client to make API requests using the stored API key.
- **Testing**: Included instructions on how to start the Laravel development server and test the API integration.

This guide should help Laravel developers integrate your API into their applications without needing to clone a repository, focusing solely on API key usage and endpoint interaction.