PHPackages                             sauls/xkcd-api-client - 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. [API Development](/categories/api)
4. /
5. sauls/xkcd-api-client

ActiveLibrary[API Development](/categories/api)

sauls/xkcd-api-client
=====================

Sauls xkcd.com api client

v1.0.0(8y ago)131MITPHPPHP &gt;=7.2

Since Mar 7Pushed 8y agoCompare

[ Source](https://github.com/sauls/xkcd-api-client)[ Packagist](https://packagist.org/packages/sauls/xkcd-api-client)[ RSS](/packages/sauls-xkcd-api-client/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Sauls xkcd api client
=====================

[](#sauls-xkcd-api-client)

[![Build Status](https://camo.githubusercontent.com/1a96664def9907fec9525f96ec89e9df63dd25e0cf0f9f65ed06186d8afe5b85/68747470733a2f2f7472617669732d63692e6f72672f7361756c732f786b63642d6170692d636c69656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/sauls/xkcd-api-client)[![Packagist](https://camo.githubusercontent.com/7e0b20f7a2340d6eb9ab3a2a3bdd9584a740c53446a89097c7c85a7d80e640b0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7361756c732f786b63642d6170692d636c69656e742e737667)](https://packagist.org/packages/sauls/xkcd-api-client)[![Total Downloads](https://camo.githubusercontent.com/981b6b04d9fd8a992bb9625699dea298ec0d4572cb8875cf4077a915b60fc6f8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7361756c732f786b63642d6170692d636c69656e742e737667)](https://packagist.org/packages/sauls/xkcd-api-client)[![Coverage Status](https://camo.githubusercontent.com/541780363b4a02a722d044b6e1e4102c08b9801330cbd47b1aebe8abbfade818/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6769746875622f7361756c732f786b63642d6170692d636c69656e742e737667)](https://coveralls.io/github/sauls/xkcd-api-client?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3dee5bfba347480d90af402d38dee85cafca25a0249989709e5a0eca95e9f15e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7361756c732f786b63642d6170692d636c69656e742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sauls/xkcd-api-client/?branch=master)[![License](https://camo.githubusercontent.com/aec853647cc9b728db79a25e4f4761ab1f00502c1ff535a7af3ec7d3a3904e55/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7361756c732f786b63642d6170692d636c69656e742e737667)](https://packagist.org/packages/sauls/xkcd-api-client)

Sauls xkcd.com api client.

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

[](#requirements)

PHP &gt;= 7.2

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

[](#installation)

### Using composer

[](#using-composer)

```
$ composer require sauls/xkcd-api-client
```

### Apppend the composer.json file manually

[](#apppend-the-composerjson-file-manually)

```
{
    "require": {
        "sauls/xkcd-api-client": "^1.0"
    }
}
```

Client configuration
--------------------

[](#client-configuration)

Client default configuration that can be overridden by passing new values on client creation.

```
[
    'client' => [
        'url' => [
            'latest' => '/info.0.json',
            'comic' => '/{num}/info.0.json',
        ],
        'cache' => [
            'prefix' => '__xkcd__',
            'ttl' => 720,
        ],
    ],
    'http_client' => [
        'base_uri' => 'http://xkcd.com',
    ],
]
```

The info object
---------------

[](#the-info-object)

This object is returned when you call the `getLatest`, `getRandom` and `get($num)` methods

```
class Info
{
    private $month;
    private $num;
    private $link;
    private $year;
    private $news;
    private $safeTitle;
    private $transcript;
    private $alt;
    private $img;
    private $title;
    private $day;

    /* getters and setters */
}
```

Usage without cache
-------------------

[](#usage-without-cache)

```
Sauls\Component\xkcd\Api\Client\Client;

$client = new Client();

$latestInfo = $client->getLatest(); // returns latest xkcd.com comic info
$randomInfo = $client->getRandom(); // returns random xkcd.com comic info
$concreteInfo = $client->get(614); // returns concrete xkcd.com comic info
```

Usage with cache
----------------

[](#usage-with-cache)

Uses `symfony/cache` component to cache the responses. For how to configure the cache see [symfony/cache component documentation](https://symfony.com/doc/current/components/cache.html)

```
Sauls\Component\xkcd\Api\Client\Client;

$client = new Client();

$cache = new FilesystemCache(/* parameters */);

$client->setCache($cache);

$latestInfo = $client->getLatest();
```

Exceptions
----------

[](#exceptions)

- `ComicNotFoundException` - is thrown when requested comic was not found e.g. the xkcd api returns `404` response
- `ServiceDownException` - is thrown on all other response statuses
- `XkcdClientException` - is thrown when there is something wrong with your configuration or when errors occur.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity58

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

2990d ago

### Community

Maintainers

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

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sauls-xkcd-api-client/health.svg)

```
[![Health](https://phpackages.com/badges/sauls-xkcd-api-client/health.svg)](https://phpackages.com/packages/sauls-xkcd-api-client)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[commercetools/commercetools-sdk

The official PHP SDK for the commercetools Composable Commerce APIs

19281.5k](/packages/commercetools-commercetools-sdk)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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