{"id":48463800,"url":"https://github.com/glook/apist","last_synced_at":"2026-04-07T03:30:47.278Z","repository":{"id":346619463,"uuid":"1055645552","full_name":"glook/apist","owner":"glook","description":"Package that provides API-like access to HTML pages via CSS-selector-based scraping","archived":false,"fork":false,"pushed_at":"2026-03-25T14:53:20.000Z","size":117,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-03-25T21:48:22.595Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/glook.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-12T15:19:17.000Z","updated_at":"2026-03-25T14:48:37.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/glook/apist","commit_stats":null,"previous_names":["glook/apist"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/glook/apist","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glook%2Fapist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glook%2Fapist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glook%2Fapist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glook%2Fapist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/glook","download_url":"https://codeload.github.com/glook/apist/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glook%2Fapist/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31499191,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T03:10:19.677Z","status":"ssl_error","status_checked_at":"2026-04-07T03:10:13.982Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-07T03:30:45.812Z","updated_at":"2026-04-07T03:30:47.269Z","avatar_url":"https://github.com/glook.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Glook Apist\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/glook/apist.svg?style=flat)](https://packagist.org/packages/glook/apist)\n[![Total Downloads](https://img.shields.io/packagist/dm/glook/apist.svg?style=flat)](https://packagist.org/packages/glook/apist)\n[![Tests](https://github.com/glook/apist/workflows/Tests/badge.svg)](https://github.com/glook/apist/actions?query=workflow%3ATests)\n[![License](https://img.shields.io/packagist/l/glook/apist.svg?style=flat)](LICENSE)\n\n\u003e Fork of [sleeping-owl/apist](https://github.com/sleeping-owl/apist) with updated dependencies.\n\nGlook Apist is a small library which allows you to access any site in api-like style, based on html parsing.\n\n## Install the Package\n\nFrom [Packagist](https://packagist.org/packages/glook/apist):\n\n```\n composer require glook/apist\n```\n\n## Usage\n\n### Basic example\n\nCreate a class that extends `Apist` and define your API methods using blueprints — arrays that map keys to CSS selectors\nwith extraction chains:\n\n```php\nuse glook\\apist\\Apist;\n\nclass WikiApi extends Apist\n{\n\n\tpublic function getBaseUrl(): ?string\n\t{\n\t\treturn 'https://en.wikipedia.org';\n\t}\n\n\tpublic function index()\n\t{\n\t\treturn $this-\u003eget('/wiki/Main_Page', [\n\t\t\t'welcome_message'  =\u003e Apist::filter('#mp-topbanner div:first')-\u003etext()-\u003emb_substr(0, -1),\n\t\t\t'portals'          =\u003e Apist::filter('a[title^=\"Portal:\"]')-\u003eeach([\n\t\t\t\t'link'  =\u003e Apist::current()-\u003eattr('href')-\u003ecall(function ($href)\n\t\t\t\t{\n\t\t\t\t\treturn $this-\u003egetBaseUri() . $href;\n\t\t\t\t}),\n\t\t\t\t'label' =\u003e Apist::current()-\u003etext()\n\t\t\t]),\n\t\t\t'languages'        =\u003e Apist::filter('#p-lang li a[title]')-\u003eeach([\n\t\t\t\t'label' =\u003e Apist::current()-\u003etext(),\n\t\t\t\t'lang'  =\u003e Apist::current()-\u003eattr('title'),\n\t\t\t\t'link'  =\u003e Apist::current()-\u003eattr('href')-\u003ecall(function ($href)\n\t\t\t\t{\n\t\t\t\t\treturn 'https:' . $href;\n\t\t\t\t})\n\t\t\t]),\n\t\t\t'sister_projects'  =\u003e Apist::filter('#mp-sister b a')-\u003eeach()-\u003etext(),\n\t\t\t'featured_article' =\u003e Apist::filter('#mp-tfa')-\u003ehtml()\n\t\t]);\n\t}\n}\n```\n\nResult:\n\n```json\n{\n  \"welcome_message\": \"Welcome to Wikipedia\",\n  \"portals\": [\n    {\n      \"link\": \"https:\\/\\/en.wikipedia.org\\/wiki\\/Portal:Arts\",\n      \"label\": \"Arts\"\n    },\n    {\n      \"link\": \"https:\\/\\/en.wikipedia.org\\/wiki\\/Portal:Biography\",\n      \"label\": \"Biography\"\n    }\n  ],\n  \"languages\": [\n    {\n      \"label\": \"Simple English\",\n      \"lang\": \"Simple English\",\n      \"link\": \"https:\\/\\/simple.wikipedia.org\\/wiki\\/\"\n    }\n  ],\n  \"sister_projects\": [\n    \"Commons\",\n    \"MediaWiki\"\n  ],\n  \"featured_article\": \"\u003cdiv style=\\\"float: left;\\\"\u003e...\u003c/div\u003e\"\n}\n```\n\n### Blueprint concept\n\nA **blueprint** is an array (or a single selector) that describes how to extract structured data from HTML. Each value\nin the blueprint is an `ApistSelector` — a chain of CSS selector + extraction methods.\n\n```php\n// Array blueprint — returns associative array\n$this-\u003eget('/page', [\n    'title'   =\u003e Apist::filter('h1')-\u003etext(),\n    'content' =\u003e Apist::filter('.body')-\u003ehtml(),\n]);\n\n// Single selector blueprint — returns a single value\n$this-\u003eget('/page', Apist::filter('h1')-\u003etext());\n\n// No blueprint — returns raw HTML content\n$this-\u003eget('/page');\n```\n\n### Static helpers\n\n- `Apist::filter('.selector')` — creates an `ApistSelector` bound to a CSS selector\n- `Apist::current()` — references the current element inside `each()` iterations\n\n### HTTP methods\n\nAll standard HTTP methods are supported:\n\n```php\n$this-\u003eget($url, $blueprint, $options);\n$this-\u003epost($url, $blueprint, $options);\n$this-\u003eput($url, $blueprint, $options);\n$this-\u003epatch($url, $blueprint, $options);\n$this-\u003edelete($url, $blueprint, $options);\n$this-\u003ehead($url, $blueprint, $options);\n```\n\nThe `$options` array is passed directly to Guzzle's request options.\n\n### Filter methods\n\nExtraction methods available in selector chains:\n\n| Method            | Description               |\n|-------------------|---------------------------|\n| `text()`          | Get text content          |\n| `html()`          | Get inner HTML            |\n| `attr('name')`    | Get attribute value       |\n| `hasAttr('name')` | Check if attribute exists |\n| `exists()`        | Check if element exists   |\n\nNavigation:\n\n| Method               | Description                        |\n|----------------------|------------------------------------|\n| `first()`            | First matched element              |\n| `last()`             | Last matched element               |\n| `eq($index)`         | Element at index                   |\n| `next()`             | Next sibling                       |\n| `prev()`             | Previous sibling                   |\n| `children()`         | Child elements                     |\n| `closest($selector)` | Closest ancestor matching selector |\n\nIteration:\n\n| Method             | Description                     |\n|--------------------|---------------------------------|\n| `each($blueprint)` | Iterate over matched elements   |\n| `each()`           | Returns collection for chaining |\n\nTransformation:\n\n| Method                           | Description               |\n|----------------------------------|---------------------------|\n| `call($callback)`                | Apply custom callback     |\n| `check($condition, $then)`       | Conditional logic         |\n| `then($blueprint)`               | Apply blueprint if truthy |\n| `trim()`                         | Trim whitespace           |\n| `intval()`                       | Cast to integer           |\n| `floatval()`                     | Cast to float             |\n| `str_replace($search, $replace)` | String replacement        |\n| `mb_substr($start, $length)`     | Multibyte substring       |\n\nAny global PHP function can also be used in the chain (e.g., `strtoupper`, `strip_tags`).\n\n### Error handling\n\nBy default, HTTP errors are suppressed and returned as structured error responses:\n\n```php\n$api-\u003esetSuppressExceptions(false); // throw exceptions on HTTP errors\n```\n\n### Access to Guzzle response\n\nAfter a request, you can access the underlying Guzzle response:\n\n```php\n$result = $api-\u003eindex();\n$response = $api-\u003egetLastMethod()-\u003egetResponse();\n$statusCode = $response-\u003egetStatusCode();\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Supported PHP Versions\n\nThat package has been tested on the following PHP versions:\n\n- PHP 7.4\n- PHP 8.0\n- PHP 8.1\n- PHP 8.2\n- PHP 8.3\n- PHP 8.4\n- PHP 8.5\n\n## Copyright and License\n\nOriginally written by [Sleeping Owl](https://github.com/sleeping-owl) and released under the MIT License.\n\nFork maintained by [Andrey Polyakov](https://github.com/glook).\n\nSee the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglook%2Fapist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglook%2Fapist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglook%2Fapist/lists"}