PHP code example of lfvcodes / microbridge-php

1. Go to this page and download the library: Download lfvcodes/microbridge-php 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/ */

    

lfvcodes / microbridge-php example snippets



re_once 'src/RequestContext.php';
code here...


icroBridge\MicroBridge;

try {
    // Create client with POST method
    $client = new MicroBridge('POST');
    
    // Make request with data payload
    $response = $client->request('./api/users.php', [
        'name' => 'John Doe',
        'email' => '[email protected]'
    ]);
    
    print_r($response);
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}


icroBridge\MicroBridge;

try {
    $client = new MicroBridge('GET');
    
    // Method 1: URL with query string
    $response = $client->request('./api/users.php?id=4');
    
    // Method 2: Separate parameters
    $response = $client->request('./api/users.php', ['id' => 4]);
    
    print_r($response);
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}


icroBridge\MicroBridge;

try {
    $client = new MicroBridge('PUT');
    
    $response = $client->request('./api/users.php', 
        ['id' => 1, 'name' => 'Updated Name'],
        ['Authorization' => 'Bearer token123']
    );
    
    print_r($response);
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}
bash
composer 

your-project/
├── src/
│   ├── MicroBridge.php
│   ├── RequestContext.php
│   └── MockPhpStream.php
└── your-code.php
bash
# Run basic usage examples
php examples/basic-usage.php

# Run chained requests demonstration
php examples/chained-requests.php

# Run error handling examples
php examples/error-handling.php
bash
# Start PHP's built-in development server
php -S localhost:8000

# Then visit in your browser:
# http://localhost:8000/examples/basic-usage.php
# http://localhost:8000/examples/chained-requests.php
# http://localhost:8000/examples/error-handling.php