ppoulpe/apicalypse

此包已弃用,不再维护。未建议替代包。

APIcalypse查询语言构建器

1.0.0 2020-03-11 12:53 UTC

This package is auto-updated.

Last update: 2020-11-05 11:23:40 UTC


README

Apicalypse是一种用于从简单的REST API获取数据的查询语言。

此项目旨在提供一组方法,使用APIcalypse语法在API上创建和执行查询。

要了解更多关于语法的知识,请访问 https://apicalypse.io/

安装

使用 composer require 获取项目的最新稳定版本。

composer require ppoulpe/apicalypse

用法

一组方法使您可以轻松快速地创建查询,并确保语法始终正确。

目前,提供 fieldssearchwhereoutlimit 过滤器。随着开发的进展,将添加更多过滤器到查询构建器中。

use Apicalypse\Query;

$query = (new Query())
    ->fields('title', 'summary')
    ->search('Tomb Raider')
    ->where('title','Tomb Raider')
    ->where('id', 1090)
    ->sort('title')
    ->limit(10);

// Will echo : search "Tomb Raider"; fields title,summary; where title = "Tomb Raider",id = 1090; limit 10; sort title;
echo $query;

可以使用嵌入式HTTP模块直接向API发送请求并获取响应。

use Apicalypse\Query;

$formattedResponse = (new Query())
    ->fields('title', 'summary')
    ->search('Tomb Raider')
    ->where('title','Tomb Raider')
    ->where('id', 1090)
    ->sort('title')
    ->limit(10)
    ->request("https://my-awesome-api.com/games");

// Will echo : [{title: "Tomb Raider", summary: "This is a summary"}]
echo $formattedResponse;

单元测试

运行所有单元测试

./vendor/bin/phpunit tests