dev-master 2020-09-23 22:27 UTC

This package is auto-updated.

Last update: 2024-05-24 07:25:24 UTC


Build Status Scrutinizer Code Quality

Latest Stable Version Latest Unstable Version Total Downloads License Monthly Downloads Daily Downloads composer.lock

GitHub Code Size GitHub Repo Size GitHub Last Commit GitHub Activity GitHub Issues


The UK Government has provided an API for accessing COVID data. The documentation is poor, see , and if the structure parameter is missing the API call redirects to the documentation above (!).

I am not sure about how often and indeed how soon the data is updated, but hopefully it proves of use to the PHP community.


Existing PHP Environment

If you have an existing PHP environment, install as follows:

composer require suilven/uk-covid-govt-api-client


A Docker environment is provided for, primarily to run unit tests

sudo docker-compose up -d phpcli
sudo docker-compose exec /bin/bash
composer install


Get An Area Type

An area type is mandatory, but defaults to a level of nation. This can be set as follows:

use Suilven\CovidAPIClient\Factory\AreaTypeFactory;
use Suilven\CovidAPIClient\Filter\AreaType;

$factory = new AreaTypeFactory();
$areaType = $factory->getAreaType(AreaType::NATION);
public const OVERVIEW = 'overview';
public const NATION = 'nation';
public const REGION = 'region';
public const NHS_REGION = 'nhsRegion';
public const UPPER_TIER = 'utla';
public const LOWER_TIER = 'ltla';

Valid values for AreaType are as follows:

  • AreaType::OVERVIEW
  • AreaType::NATION
  • AreaType::REGION
  • AreaType::NHS_REGION
  • AreaType::UPPER_TIER
  • AreaType::LOWER_TIER

Valid values for upper and lower tier area names can be found in the docs directory.

Add a Filter

$factory = new AreaTypeFactory();
$areaType = $factory->getAreaType(AreaType::UPPER_TIER);
$client = new APIClient();
$filter = new Filter();
$filter->setAreaName('Blackburn with Darwen');
$result = $client->getData([$filter]);

One can set a date, an area code or area name as above.

Get Results

Each recodr (of an array) is a Suilven\CovidAPIClient\Model<SingleEntry object.

$record = $result->getRecords();

Get Data For An Individual Result

$this->assertEquals('S12000027', $record->getAreaCode();
$this->assertEquals('Shetland Islands', $record->getAreaName();
$this->assertEquals('2020-09-21', $record->getDate())


This is a functional but rough implementation, although well tested.

I still do not fully understand how the data behind the API is updated, this is a bit of a black box.