fox-hound-ltd / mixture-api-client

GraphQL & REST API 客户端

0.1.0 2018-11-08 09:22 UTC

This package is not auto-updated.

Last update: 2024-09-21 08:15:52 UTC


README

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

概要

支持GraphQL和REST的Client库

PHP版本的GraphQL & REST客户端

基于GuzzleHttp Base

安装

使用Composer

$ composer require fox-hound-ltd/mixture-api-client

使用示例

简单模式

<?php
use MixtureApiClient\ClientBuilder;

$client = ClientBuilder::build(
    'https://hogehoge.com/graphql'
);

$query = <<<'QUERY'
query foo(id: 11){
 id
 name
}
QUERY;

$response = $client->query($query);

使用JsonWebToken的情况

<?php
use MixtureApiClient\ClientBuilder;
use MixtureApiClient\JWT;

$jwt= new JWT();

$payload['secret_key'] = 'fiwivkbbeec1e958a6c5dd31336242607c0887754b1d43ebf071fb2890533d611a';

$headers = [
    'Authorization' => $jwt->makeToken('secret', $payload),
];

$config = ['headers' => $headers];

$client = ClientBuilder::build(
    'https://hogehoge.com/graphql',
    $config
);

$query = <<<'QUERY'
query GetHoge($target_id: ID, $member_name: String) {
  foo(id: $target_id) {
    id_foo
    bar (name: $member_name) {
      id_bar
    }
  }
}
QUERY;

$variables = [
    'target_id' => 11,
    'member_name' => 'bar',
];
$response = $client->query($query, $variables);

测试相关

$ composer test

许可证

Apache 2.0许可证。更多详细信息请参阅LICENSE