Skip to content

Latest commit

 

History

History
88 lines (60 loc) · 1.96 KB

index.md

File metadata and controls

88 lines (60 loc) · 1.96 KB

Quickstart

Installation

The best way to install FreezyBee/Restu is using Composer:

$ composer require freezy-bee/restu

With Nette 2.3 and newer, you can enable the extension using your neon config.

extensions:
	restu: FreezyBee\Restu\DI\RestuExtension

Minimal configuration

restu:
	apiKey: **your api key**

Full configuration

restu:
	apiKey: **your api key**
	restaurantId: **restaurant id**
    apiUrl: https://rest-api.restu.cz/
    version: v1

Debugging

The extension monitors request and response, when in debug mode. All that information is available in Tracy panel

Example

class HomepagePresenter extends Presenter
{
    /** @var \FreezyBee\Restu\Api @inject */
    public $api;

    public function actionTest()
    {

        try {
            // get restaurants
            $result = $this->api->call('GET', 'restaurants');

            // create restaurant service (restaurantId is defined in config)
            /** @var \FreezyBee\Restu\Service\Restaurants $restaurantsService1 **/
            $restaurantsService1 = $this->api->createService(\FreezyBee\Restu\Service\Restaurants::class);

            // create restaurant service (restaurantId defined in parameter)
            /** @var \FreezyBee\Restu\Service\Restaurants $restaurantsService2 **/
            $restaurantsService2 = $this->api->createService(\FreezyBee\Restu\Service\Restaurants::class, 'rest2', ['id' => 10000]);

            // create user service with language parameter
            /** @var \FreezyBee\Restu\Service\User $userService **/
            $userService = $this->api->createService(\FreezyBee\Restu\Service\User::class, ['language' => 'en']);
            
            $menus = $restaurantService1->getMenus();
            
            ...

        } catch (RestuException $e) {
            Debugger::log($e);
        }
    }
}