kazakevic/strapi-wrapper

wrapper for Strapi headless CMS

2.0.1 2024-02-12 21:40 UTC

This package is auto-updated.

Last update: 2024-10-12 23:05:44 UTC


README

Latest Stable Version Total Downloads License PHP Version Require

⚙️ Install
composer require kazakevic/strapi-wrapper
⚙️ Usage
  • Setup Client
    • You can use any HTTP client that implements Psr\Http\Client\ClientInterface
$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