PHPackages                             glook/apist - 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. glook/apist

ActiveLibrary[API Development](/categories/api)

glook/apist
===========

Package to provide api-like access to foreign sites based on html parsing (fork of sleeping-owl/apist package with updated dependencies)

2.1.1(3mo ago)0112↑100%MITPHPPHP &gt;=7.4CI passing

Since Mar 24Pushed 3mo agoCompare

[ Source](https://github.com/glook/apist)[ Packagist](https://packagist.org/packages/glook/apist)[ Docs](https://github.com/glook/apist)[ RSS](/packages/glook-apist/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (5)Dependencies (5)Versions (12)Used By (0)

Glook Apist
-----------

[](#glook-apist)

[![Latest Stable Version](https://camo.githubusercontent.com/ff8301614a80d17e4b42c8c0ddb4c721407f0f01a4f40a97a8b499da99611a57/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f676c6f6f6b2f61706973742e7376673f7374796c653d666c6174)](https://packagist.org/packages/glook/apist)[![Total Downloads](https://camo.githubusercontent.com/1f34ad511f6a9c1985ce6b13d3e599406df038b04f3822303eabd59f5e935a8c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f676c6f6f6b2f61706973742e7376673f7374796c653d666c6174)](https://packagist.org/packages/glook/apist)[![Tests](https://github.com/glook/apist/workflows/Tests/badge.svg)](https://github.com/glook/apist/actions?query=workflow%3ATests)[![License](https://camo.githubusercontent.com/900df23413f8468f5f713fadcdbabcffa622316787d0991424e7812d71630029/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f676c6f6f6b2f61706973742e7376673f7374796c653d666c6174)](LICENSE)

> Fork of [sleeping-owl/apist](https://github.com/sleeping-owl/apist) with updated dependencies.

Glook Apist is a small library which allows you to access any site in api-like style, based on html parsing.

Install the Package
-------------------

[](#install-the-package)

From [Packagist](https://packagist.org/packages/glook/apist):

```
 composer require glook/apist

```

Usage
-----

[](#usage)

### Basic example

[](#basic-example)

Create a class that extends `Apist` and define your API methods using blueprints — arrays that map keys to CSS selectors with extraction chains:

```
use glook\apist\Apist;

class WikiApi extends Apist
{

	public function getBaseUrl(): ?string
	{
		return 'https://en.wikipedia.org';
	}

	public function index()
	{
		return $this->get('/wiki/Main_Page', [
			'welcome_message'  => Apist::filter('#mp-topbanner div:first')->text()->mb_substr(0, -1),
			'portals'          => Apist::filter('a[title^="Portal:"]')->each([
				'link'  => Apist::current()->attr('href')->call(function ($href)
				{
					return $this->getBaseUri() . $href;
				}),
				'label' => Apist::current()->text()
			]),
			'languages'        => Apist::filter('#p-lang li a[title]')->each([
				'label' => Apist::current()->text(),
				'lang'  => Apist::current()->attr('title'),
				'link'  => Apist::current()->attr('href')->call(function ($href)
				{
					return 'https:' . $href;
				})
			]),
			'sister_projects'  => Apist::filter('#mp-sister b a')->each()->text(),
			'featured_article' => Apist::filter('#mp-tfa')->html()
		]);
	}
}
```

Result:

```
{
  "welcome_message": "Welcome to Wikipedia",
  "portals": [
    {
      "link": "https:\/\/en.wikipedia.org\/wiki\/Portal:Arts",
      "label": "Arts"
    },
    {
      "link": "https:\/\/en.wikipedia.org\/wiki\/Portal:Biography",
      "label": "Biography"
    }
  ],
  "languages": [
    {
      "label": "Simple English",
      "lang": "Simple English",
      "link": "https:\/\/simple.wikipedia.org\/wiki\/"
    }
  ],
  "sister_projects": [
    "Commons",
    "MediaWiki"
  ],
  "featured_article": "..."
}
```

### Blueprint concept

[](#blueprint-concept)

A **blueprint** is an array (or a single selector) that describes how to extract structured data from HTML. Each value in the blueprint is an `ApistSelector` — a chain of CSS selector + extraction methods.

```
// Array blueprint — returns associative array
$this->get('/page', [
    'title'   => Apist::filter('h1')->text(),
    'content' => Apist::filter('.body')->html(),
]);

// Single selector blueprint — returns a single value
$this->get('/page', Apist::filter('h1')->text());

// No blueprint — returns raw HTML content
$this->get('/page');
```

### Static helpers

[](#static-helpers)

- `Apist::filter('.selector')` — creates an `ApistSelector` bound to a CSS selector
- `Apist::current()` — references the current element inside `each()` iterations

### HTTP methods

[](#http-methods)

All standard HTTP methods are supported:

```
$this->get($url, $blueprint, $options);
$this->post($url, $blueprint, $options);
$this->put($url, $blueprint, $options);
$this->patch($url, $blueprint, $options);
$this->delete($url, $blueprint, $options);
$this->head($url, $blueprint, $options);
```

The `$options` array is passed directly to Guzzle's request options.

### Filter methods

[](#filter-methods)

Extraction methods available in selector chains:

MethodDescription`text()`Get text content`html()`Get inner HTML`attr('name')`Get attribute value`hasAttr('name')`Check if attribute exists`exists()`Check if element existsNavigation:

MethodDescription`first()`First matched element`last()`Last matched element`eq($index)`Element at index`next()`Next sibling`prev()`Previous sibling`children()`Child elements`closest($selector)`Closest ancestor matching selectorIteration:

MethodDescription`each($blueprint)`Iterate over matched elements`each()`Returns collection for chainingTransformation:

MethodDescription`call($callback)`Apply custom callback`check($condition, $then)`Conditional logic`then($blueprint)`Apply blueprint if truthy`trim()`Trim whitespace`intval()`Cast to integer`floatval()`Cast to float`str_replace($search, $replace)`String replacement`mb_substr($start, $length)`Multibyte substringAny global PHP function can also be used in the chain (e.g., `strtoupper`, `strip_tags`).

### Error handling

[](#error-handling)

By default, HTTP errors are suppressed and returned as structured error responses:

```
$api->setSuppressExceptions(false); // throw exceptions on HTTP errors
```

### Access to Guzzle response

[](#access-to-guzzle-response)

After a request, you can access the underlying Guzzle response:

```
$result = $api->index();
$response = $api->getLastMethod()->getResponse();
$statusCode = $response->getStatusCode();
```

Testing
-------

[](#testing)

```
composer test
```

Supported PHP Versions
----------------------

[](#supported-php-versions)

That package has been tested on the following PHP versions:

- PHP 7.4
- PHP 8.0
- PHP 8.1
- PHP 8.2
- PHP 8.3
- PHP 8.4
- PHP 8.5

Copyright and License
---------------------

[](#copyright-and-license)

Originally written by [Sleeping Owl](https://github.com/sleeping-owl) and released under the MIT License.

Fork maintained by [Andrey Polyakov](https://github.com/glook).

See the [LICENSE](LICENSE) file for details.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance82

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 55.9% 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 ~0 days

Total

5

Last Release

90d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f2a24f7c11b723d30417c0182a228d29d4b85bfb58eb2729235fa7093b84320?d=identicon)[glook](/maintainers/glook)

---

Top Contributors

[![sleeping-owl](https://avatars.githubusercontent.com/u/9197310?v=4)](https://github.com/sleeping-owl "sleeping-owl (33 commits)")[![glook](https://avatars.githubusercontent.com/u/545998?v=4)](https://github.com/glook "glook (24 commits)")[![zamarawka](https://avatars.githubusercontent.com/u/9637438?v=4)](https://github.com/zamarawka "zamarawka (2 commits)")

---

Tags

apicrawler

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/glook-apist/health.svg)

```
[![Health](https://phpackages.com/badges/glook-apist/health.svg)](https://phpackages.com/packages/glook-apist)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[spatie/crawler

Crawl all internal links found on a website

2.8k17.7M58](/packages/spatie-crawler)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3661.2M46](/packages/tencentcloud-tencentcloud-sdk-php)[sleeping-owl/apist

Package to provide api-like access to foreign sites based on html parsing

3095.3k](/packages/sleeping-owl-apist)[files.com/files-php-sdk

Files.com PHP SDK

2478.1k](/packages/filescom-files-php-sdk)[sproutcms/cms

Enterprise content management and framework

242.2k4](/packages/sproutcms-cms)

PHPackages © 2026

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