alexkratky / apix
Class to work with API rate limits.
Requires
- php: >=7.0
- alexkratky/cachex: ^1.0.0
- alexkratky/panx-utils: ^1.0.0
- alexkratky/requestx: ^1.0.0
- alexkratky/routex: ^1.0.0
- alexkratky/url: ^1.0.0
This package is auto-updated.
Last update: 2024-11-11 22:05:39 UTC
README
Class to work with API rate limits.
Installation
composer require alexkratky/apix
Usage
require 'vendor/autoload.php'; use AlexKratky\API; use AlexKratky\Cache; Cache::setDirectory(__DIR__ . '/cache/'); $API_Endpoint = new API('v1'); if(!$API_Endpoint->request(new URL())) { echo $API_Endpoint->error(); exit(); } //valid API request. Continue with code.
Information
API class is class to work with API request. On created API endpoint creates API interface, which will handle all requests. To response to the request, the request must contain valid API key (One from api_keys
table). The valid means, that the key must exists and must have not reached the rate limits. If the corresponding route have template file(s), it will be required, but if have function, the function will be executed, and if the function return something, the result will outputed as beautify json string (The result will be encoded using json_encode) and also it will save he response as cache file. This cache file name is combination of API key and URL.