luyadev/luya-headless

LUYA 无头 API 客户端

安装次数: 21,015

依赖项: 3

建议者: 0

安全: 0

星标: 10

关注者: 5

分支: 2

开放问题: 0

类型:luya-core

2.10.1 2023-09-13 08:46 UTC

README

LUYA Logo

LUYA 无头客户端

一个客户端库,用于访问 LUYA API(或任何其他 REST API)的内容。

LUYA Tests Latest Stable Version Maintainability Test Coverage Total Downloads

安装

将 LUYA 无头客户端库添加到您的 composer.json 文件中

composer require luyadev/luya-headless

简介

关于如何使用自定义端点使用无头库的快速简介:创建 Api 类(这与 Active Record 模式非常相似)

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

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

有了新的 ApiCars 类,您现在可以插入、更新或检索数据

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;
}

文档

请参阅完整文档,了解如何进行 put、delete 或 post 请求,处理分页或访问 CMS 块。

开发和贡献