PHP code example of lambry / apison

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

    

lambry / apison example snippets



use Lambry\Apison\Frontend\Api;

// Get all jobs
Api::get('jobs')->all();

// Get full forcast with just humidity and temperature fields
Api::get('forcast')->with(['humidity', 'temperature'])->all();

// Get all contacts with a role of either sales or marketing
Api::get('contacts')->where('role', ['sales', 'marketing'])->all();

// Get the last 10 listings that have a price greater than 100
Api::get('listings')->where('price', 'gt', 100)->last(10);

// Get the first 20 events offset by 20 that are not in the sports category
Api::get('events')->where('category', 'not', 'sports')->first(20, 20);

// Get the title and price for all products that are currently on sale and are priced under 50
Api::get('products')->where('sale', true)->and('price', 'lt', 50)->with(['title', 'price'])->all();


// Setting api keys
add_filter('apison/key', function($slug) {
    switch ($slug) {
        case 'events':
            return env('EVENTS_API_KEY');
            break;
        case 'weather':
            return env('WEATHER_API_KEY');
            break;
    }
});

// Adding new cache durations
add_filter('apison/cache', function($options) {
    $options['10080'] = '1 week';

    return $options;
});

// Altering permissions to see the plugin admin
add_filter('apison/permission', function() {
    return 'manage_network';
});