PHPackages                             p-chess/api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. p-chess/api

ActiveLibrary[HTTP &amp; Networking](/categories/http)

p-chess/api
===========

PHP client for chess-api.com using PSR-18 HTTP Client

v1.0.0(3mo ago)12MITPHPPHP ^8.2CI passing

Since Feb 15Pushed 1mo agoCompare

[ Source](https://github.com/p-chess/api)[ Packagist](https://packagist.org/packages/p-chess/api)[ RSS](/packages/p-chess-api/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (5)Versions (3)Used By (0)

Chess API Client
================

[](#chess-api-client)

A PHP client for [chess-api.com](https://chess-api.com/) using PSR-18 HTTP Client.

Requirements
------------

[](#requirements)

- PHP 8.2+
- PSR-18 HTTP Client implementation (e.g. Symfony HttpClient, Guzzle)
- PSR-17 HTTP Factory implementation

Installation
------------

[](#installation)

```
composer require p-chess/api
```

If you want to use Symfony HttpClient:

```
composer require nyholm/psr7 symfony/http-client
```

If you want to use Guzzle:

```
composer require guzzlehttp/guzzle
```

Usage
-----

[](#usage)

```
use PChess\Api\ChessApiClient;

// Create the client with your PSR-18/PSR-17 implementations
$client = new ChessApiClient(
    $httpClient,        // PSR-18 ClientInterface
    $requestFactory,    // PSR-17 RequestFactoryInterface
    $streamFactory,     // PSR-17 StreamFactoryInterface
);

// Get the best move for a position
$fen = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1';
$move = $client->getBestMove($fen);
// Returns: 'e4' (or similar)

// Restrict the engine to specific moves
$move = $client->getBestMove($fen, ['e2e4', 'd2d4', 'g1f3']);
// Returns one of the allowed moves
```

### Parameters

[](#parameters)

ParameterTypeDescription`$fen``string`The chess position in FEN notation (includes side to move)`$allowedMoves``array`Optional array of allowed moves in UCI format (e.g., `['e2e4', 'd2d4']`)### Return Value

[](#return-value)

The method returns a `string` containing the best move in UCI format (e.g., `'e2e4'`).

### Exceptions

[](#exceptions)

The client throws `ChessApiException` in the following cases:

- HTTP error (non-2xx status code)
- Invalid API response (missing `move` field)
- API error (e.g., invalid FEN)

```
use PChess\Api\ChessApiException;

try {
    $move = $client->getBestMove($fen);
} catch (ChessApiException $e) {
    // Handle the error
    echo $e->getMessage();
}
```

Example with Symfony HttpClient
-------------------------------

[](#example-with-symfony-httpclient)

```
use Nyholm\Psr7\Factory\Psr17Factory;
use PChess\Api\ChessApiClient;
use Symfony\Component\HttpClient\Psr18Client;

$factory = new Psr17Factory();
$httpClient = new Psr18Client();

$chessClient = new ChessApiClient($httpClient, $factory, $factory);

$fen = 'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1';
$move = $chessClient->getBestMove($fen);

echo "Best move: $move\n";
```

Example with Guzzle
-------------------

[](#example-with-guzzle)

```
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
use PChess\Api\ChessApiClient;

$httpClient = new Client();
$factory = new HttpFactory();

$chessClient = new ChessApiClient($httpClient, $factory, $factory);

$fen = 'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1';
$move = $chessClient->getBestMove($fen);

echo "Best move: $move\n";
```

Development
-----------

[](#development)

Before exdecuting one of the following, you must execute at least once

```
docker build -t chess-api .
```

### Running Tests

[](#running-tests)

```
docker run --rm -v "$(pwd)":/srv/chess-api chess-api vendor/bin/phpunit --color=always
```

### Coding Standard

[](#coding-standard)

```
docker run --rm -v "$(pwd)":/srv/chess-api chess-api vendor/bin/php-cs-fixer --ansi
```

### Static Analysis

[](#static-analysis)

```
docker run --rm -v "$(pwd)":/srv/chess-api chess-api vendor/bin/phpstan --ansi
```

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance85

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

114d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d191f9ff3aa52357cb523c9eec3553d267128fc75e0faf9dca74f289f6604f54?d=identicon)[garak](/maintainers/garak)

---

Top Contributors

[![garak](https://avatars.githubusercontent.com/u/179866?v=4)](https://github.com/garak "garak (7 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/p-chess-api/health.svg)

```
[![Health](https://phpackages.com/badges/p-chess-api/health.svg)](https://phpackages.com/packages/p-chess-api)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B3.7k](/packages/guzzlehttp-psr7)[cakephp/cakephp

The CakePHP framework

8.8k19.1M1.7k](/packages/cakephp-cakephp)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k11](/packages/tempest-framework)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6941.5M395](/packages/drupal-core-recommended)[laudis/neo4j-php-client

Neo4j-PHP-Client is the most advanced PHP Client for Neo4j

185671.3k41](/packages/laudis-neo4j-php-client)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

84735.1k](/packages/flow-php-flow)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
