Skip to content

A client library to access content from the LUYA APIs (or any other REST API).

License

Notifications You must be signed in to change notification settings

luyadev/luya-headless

Repository files navigation

LUYA Logo

LUYA Headless Client

A client library to access content from the LUYA APIs (or any other REST API).

LUYA Tests Latest Stable Version Maintainability Test Coverage Total Downloads

Installation

Add the LUYA headless client library to your composer.json:

composer require luyadev/luya-headless

Intro

Quick intro about how to use the headless library with a custom Endpoint: Create the Api Class (this very similar to Active Record pattern):

class ApiCars extends \luya\headless\ActiveEdnpoint
{
    public $id;
    public $name;
    public $year;

    public function getEndpointName()
    {
        return '{{api-cars}}';
    }
}

With the new ApiCars class you can now insert, update or fetch data:

use luya\headless\Client;

// build client object with token and server infos
$client = new Client('API_TOKEN', 'http://localhost/luya-kickstarter/public_html');

// create new value
$car = new ApiCars();
$car->name = 'BMW';
$car->year = 2019;
$car->save($client);

// find a given user by its ID
$car = ApiCars::viewOne(1, $client);
echo $car->name; // BMW
echo $car->year; // 2019

// update an existing value
$car->year = '2018';
$car->save($client);

// iterate all cars
$users = ApiCars::find()->setSort(['id' => SORT_ASC])->all($client);
foreach ($users->getModels() as $car) {
      echo $car->name;
}

Documentation

See the full Documentation in order to see how to make put, delete or post request, handle pagination or access the cms blocks.

Development and Contribution

About

A client library to access content from the LUYA APIs (or any other REST API).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages