PHP code example of pecyn / api-wrapper
1. Go to this page and download the library: Download pecyn/api-wrapper library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pecyn / api-wrapper example snippets
namespace App\EndPoints;
use Pecyn\ApiWrapper\EndPoint;
class CatsGetEndPoint extends EndPoint
{
protected $method = 'GET';
protected $uri = 'https://cat-fact.herokuapp.com/facts';
public function __construct(string $id)
{
$this->uri .= '/' . $id;
}
public function processResponse(\Psr\Http\Message\ResponseInterface $response)
{
if ($response->getStatusCode() == 200) {
return $response->getBody();
}
}
}
use Pecyn\ApiWrapper\Api;
$api = new \Pecyn\ApiWrapper\Api(['end_point_namespaces' => ['App\EndPoints']]);
//or
$api = new \Pecyn\ApiWrapper\Api();
$api->setEndPointNameSpaces(['App\EndPoints']);
//or extend the Api class.
//class MyApi Extends Api{
//
//protected $endPointNameSpaces = ['App\EndPoints'];
//
$facts = $api->cats->get('591d9b2f227c1a0020d26823');