krzysztof-moskalik/api-client-bundle

Bridge for KrzysztofMoskalik\ApiClient

Maintainers

Package info

github.com/KrzysztofMoskalik/api-client-bundle

Type:symfony-bundle

pkg:composer/krzysztof-moskalik/api-client-bundle

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.1.0 2026-01-21 22:55 UTC

This package is auto-updated.

Last update: 2026-02-21 23:13:20 UTC


README

Note: Project under construction!
Not All features are implemented yet!

This Project is a bridge for ApiClient (krzysztof-moskalik/api-client).

Installation

Install this package via composer:

composer require krzysztof-moskalik/api-client-bundle'

Then register bundle in config/bundles.php:

    KrzysztofMoskalik\ApiClientBundle\ApiClientBundle::class => ['all' => true],

Place configuration in config\packages\api_client.yaml file.

Configuration Reference

api_client:
    api:
        my_api:
            baseUrl: https://my-api.example.com // API host 
            auth: // remove if Api has no auth
                method: basic // basic and token are supported for now
                username: test-user // username for `basic` auth
                password: test-user-password // password for `basic` auth
                token: bG9yZW0gaXBzdW0= // token for `token` auth
                header: X-Auth-Token // header for containing token auth
            extraHeaders: // extra headers for all requests
                Accept: application/json
    resources: // resources in your api
        users:
            path: /v1/users // path to resource
            model: App\Model\User // model used to store and fetch data
            api: my_api // api related to this resource
            endpoints: // endpoints in this resource
                getAll: // endpoint label
                    requestDataPath: 'user' // path to data in request body (optional) 
                    responseDataPath: 'data' // path to data in respons body (optional) 
                    type: create // endpoint type (create | get | getAll | update | updatePartial | delete)

Usage

Just simply inject KrzysztofMoskalik\ApiClient\Client class into your service. Then you can get a repository for your model:

$repository = $this->client->getRepository(User::class);

And then call some action (which should be configured beforehand):

$users = $repository->getAll();

And that is all!

Note: For now only create, get, and getAll actions are supported!

Custom Repository

You can also create a custom repository. All you need to do is create class which extends KrzysztofMoskalik\ApiClient\AbstractRepository and override supports method:

public static function supports(): string
{
    return User::class;
}

Now you can create custom methods and call built-in ones from them.