PHPackages                             atk14/api-data-fetcher - 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. atk14/api-data-fetcher

ActiveLibrary[API Development](/categories/api)

atk14/api-data-fetcher
======================

A client for communication with ATK14 restful API

v1.12.4(3mo ago)045.6k—0%3MITPHPPHP &gt;=5.6.0

Since Sep 15Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/atk14/ApiDataFetcher)[ Packagist](https://packagist.org/packages/atk14/api-data-fetcher)[ Docs](https://github.com/atk14/ApiDataFetcher)[ RSS](/packages/atk14-api-data-fetcher/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (48)Used By (3)

ApiDataFetcher
==============

[](#apidatafetcher)

[![Build Status](https://camo.githubusercontent.com/816a2612c70d5ae2c42dcf4ab59ed5df075931422425f9370c0caa80583793e3/68747470733a2f2f7472617669732d63692e636f6d2f61746b31342f41706944617461466574636865722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/atk14/ApiDataFetcher)

Client library designed for communication with ATK14 restful API. It should be usable also for other JSON APIs.

Basic usage
-----------

[](#basic-usage)

```
$adf = new ApiDataFetcher("https://skelet.atk14.net/api/");

$data = $adf->get("articles/detail",["id" => 123]);
// or
$data = $adf->get("articles/detail/?id=123");

$title = $data["title"];

```

In fact in this example a HTTP GET request is made on URL [https://skelet.atk14.net/api/en/articles/detail/?id=123&amp;format=json](https://skelet.atk14.net/api/en/articles/detail/?id=123&format=json) and decoded JSON data is returned.

A post request can be made this way:

```
$data = $adf->post("articles/create_new",[
  "title" => "Brand New Article",
  "body" => "Once upon a time..."
]);
// or
$data = $adf->post("articles/create_new/?title=Brand+New+Article&body=Once+upon+a+time...");

```

The parameter format=json is added automatically to every request. It's a convention in ATK14 APIs. This behaviour can be disabled by setting an option in the constructor.

For completeness there are also methods *put* and *delete*.

```
$data = $adf->put("articles",[
  "title" => "Brand New Article",
  "body" => "Once upon a time..."
]);
// or
$data = $adf->put("articles/?title=Brand+New+Article&body=Once+upon+a+time...");

$data = $adf->delete("article",["id" => 123]);
// or
$data = $adf->delete("article/?id=123");

```

A method for uploading a file:

```
$data = $adf->postFile("images/create_new","/path/to/image.jpg",["title" => "Beautiful Flower", "description" => "..."]);
// or
$file_specs = [
  "path" => "/path/to/file",
  "postname" => "image",
  "name" => "flower.jpg",
  "mime_type" => "image/jpeg",
];
$data = $adf->postFile("images/create_new",$file_specs,["title" => "Beautiful Flower", "description" => "..."]);

```

A handy method for posting JSON:

```
$params = ["param1" => "val1", "param2" => "val2"];
$json = json_encode($params);

$data = $adf->postJson("endpoint",$json);
// or
$data = $adf->postJson("endpoint",$params);

```

### Handling error codes

[](#handling-error-codes)

By default ApiDataFetcher throws an exception in case of a non 2XX response code. In order to handle valid error codes on an API method, specify the codes in the option acceptable\_error\_codes.

```
$data = $adf->post("logins/create_new",[
  "login" => "johny.long",
  "password" => "JulieIsNoMore"
],[
  "acceptable_error_codes" => [
    401, // Unauthorized: Bad password
    404, // Not Found: There is no such user
  ]
]);

if(!$data){
  if($adf->getStatusCode()==401){
     // Bad password
  }
  if($adf->getStatusCode()==404){
     // There is no such user
  }
}

```

### Language

[](#language)

ApiDataFetcher tries to detect automatically currently used language in the running application and use it in the API method call.

Language can be also specified in the constructor or in the specific API method call.

```
$adf = new ApiDataFetcher("https://skelet.atk14.net/api/",["lang" => "en"]);

$data_in_english = $adf->get("articles/detail",["id" => 123]); // performs call to https://skelet.atk14.net/api/en/articles/detail/?id=123&format=json

$data_in_czech = $adf->get("articles/detail",["id" => 123],["lang" => "cs"]); // performs call to https://skelet.atk14.net/api/cs/articles/detail/?id=123&format=json

```

On a non-ATK14 API you may want to disable language considering at all.

```
$adf = new ApiDataFetcher("http://somewhere-on-the.net/json-api/",["lang" => ""]);

$data = $adf->get("articles",["id" => 123]);

```

### HTTP Basic Authentication

[](#http-basic-authentication)

Does an API require basic authentication? No problem for the ApiDataFetcher!

```
$adf = new ApiDataFetcher("https://username:password@api-on-the.net/api/");

```

### Caching

[](#caching)

```
$adf->get("articles/index",["year" => "100"],["cache" => 600]); // caching fetched content for 10 minutes (600 seconds)

// use expired cached content when an error occurs
$adf->get("articles/index",["year" => "100"],[
  "cache" => 600,
  "return_cached_content_on_error" => true
]);

```

### Tracy panel integration

[](#tracy-panel-integration)

ApiDataFetcher package comes with ApiDataFetcherPanel for easy integration into the popular debugger Tracy ()

```
$tracy_bar = Tracy\Debugger::getBar();
$tracy_bar->addPanel(new ApiDataFetcherPanel($api_data_fetcher));

```

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

[](#installation)

Use the Composer to install the ApiDataFetcher.

```
cd path/to/your/atk14/project/
composer require atk14/api-data-fetcher

```

In the project configuration file the constant API\_DATA\_FETCHER\_BASE\_URL can be defined.

```
define("API_DATA_FETCHER_BASE_URL","https://skelet.atk14.net/api/");

```

Licence
-------

[](#licence)

ApiDataFetcher is free software distributed [under the terms of the MIT license](http://www.opensource.org/licenses/mit-license)

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance81

Actively maintained with recent releases

Popularity27

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 98.3% 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

Every ~85 days

Recently: every ~75 days

Total

41

Last Release

101d ago

PHP version history (2 changes)v1.0PHP &gt;=5.3.0

v1.10.7PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6304dffbd91d7a978f98632b0e4e30d662dcdb691daadb1388a58984e98faf5c?d=identicon)[yarri](/maintainers/yarri)

---

Top Contributors

[![yarri](https://avatars.githubusercontent.com/u/974278?v=4)](https://github.com/yarri "yarri (177 commits)")[![mysutka](https://avatars.githubusercontent.com/u/974669?v=4)](https://github.com/mysutka "mysutka (3 commits)")

---

Tags

apiclientrestfulatk14

### Embed Badge

![Health badge](/badges/atk14-api-data-fetcher/health.svg)

```
[![Health](https://phpackages.com/badges/atk14-api-data-fetcher/health.svg)](https://phpackages.com/packages/atk14-api-data-fetcher)
```

###  Alternatives

[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

47073.9k5](/packages/deepseek-php-deepseek-php-client)[skeeks/yii2-google-api

Component for work with google api based on google/apiclient

1243.1k1](/packages/skeeks-yii2-google-api)

PHPackages © 2026

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