kazakevic / strapi-wrapper
wrapper for Strapi headless CMS
2.0.1
2024-02-12 21:40 UTC
Requires
- php: >=8.1
- guzzlehttp/guzzle: ^7.5
Requires (Dev)
- phpunit/phpunit: ^9
- symfony/var-dumper: ^6.1
Suggests
- guzzlehttp/guzzle: use it as HTTP client
README
⚙️ Install
composer require kazakevic/strapi-wrapper
⚙️ Usage
- Setup Client
- You can use any HTTP client that implements
Psr\Http\Client\ClientInterface
- You can use any HTTP client that implements
$httpClient = new Client(); //Guzzle http client, but can be any suitable $strapiClient = new StrapiClient( $httpClient, 'token', 'http://localhost:1338' );
- getItems
$response = $strapiClient->getItems( 'item-identifier', new PageFilter(100), new SortFilter('id', SortOrder::DESC) );
- getItemById
$jsonData = $strapiClient->getItemById('seo-pages', 534546)
- getItemsBy
$response = $strapiClient->getItemsBy( 'item-identifier', 'fieldName', 'fieldValue', new PageFilter(100), new SortFilter('id', SortOrder::DESC) );
- createItem
$jsonData = $strapiClient->createItem('topics', [ 'data' => [ 'Title' => 'Test Title', 'Slug' => 'test-slug', 'seoTitle' => 'test title', 'seoDescription' => 'test description', 'tags' => [1, 2, 2], 'videoCount' => 10 ] ]);
- updateItem
$jsonData = $strapiClient->updateItem('topics', 1, [ 'data' => [ 'Title' => 'Test Title', 'Slug' => 'test-slug', 'seoTitle' => 'test title', 'seoDescription' => 'test description', 'tags' => [1, 2, 2], 'videoCount' => 10 ] ]);
⚙️ Tests
./vendor/bin/phpunit tests