silvercomet89 / covid-19_api_php_sdk
An unofficial SDK for connecting to the UK government API via PHP
This package is auto-updated.
Last update: 2025-06-19 01:27:07 UTC
README
An unofficial SDK for connecting to the UK government COVID-19 API via PHP using curl requests.
Please note that you should always make sure this API is valid for your use-case https://coronavirus.data.gov.uk/developers-guide
Installation
To install via composer use:
composer require silvercomet89/covid-19_api_php_sdk
Basic Example
Below is a copy of a basic example, this is the same as the structure example on the developer-guide produced by the UK government except that 2 metrics they list there are no longer in their list of valid metrics. You can find this example inside the code under the examples folder.
require __DIR__ . '/../vendor/autoload.php'; // We start creating filters using the metrics. $filters = new Api\Filter\filter; $filters->addFilter(Api\Filter\filter::METRIC_AREA_TYPE, Api\Filter\areaType::AREA_TYPE_NATION); $filters->addFilter(Api\Filter\filter::METRIC_AREA_NAME, 'england'); // We start creating structures, if no display name is set the metric default will be used. $structure = new Api\Structure\structure; $structure->addStructure(Api\Structure\structure::METRIC_DATE); $structure->addStructure(Api\Structure\structure::METRIC_AREA_NAME); $structure->addStructure(Api\Structure\structure::METRIC_AREA_CODE); $structure->addStructure(Api\Structure\structure::METRIC_NEW_CASES_BY_PUBLISH_DATE); $structure->addStructure(Api\Structure\structure::METRIC_CUM_CASES_BY_PUBLISH_DATE); $structure->addStructure(Api\Structure\structure::METRIC_NEW_DEATHS_28_DAYS_BY_DEATH_DATE); $structure->addStructure(Api\Structure\structure::METRIC_CUM_DEATHS_28_DAYS_BY_DEATH_DATE); $request = new Api\request; // We set our content type here so we have a clear interface. echo $request->make_request();
Format
You can set the output format as JSON, CSV or XML. The default is JSON.
$format = new Api\Format\format; $format->format(Api\Format\format::FORMAT_JSON);
Pagination
You can take advantage of the native pagination by passing the page number you are currently on. The request results give the link to the previous or next.
$page = new Api\Page\page; $page->setPage(1);