PHPackages                             itrnka/ha-smart-http-rest-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. itrnka/ha-smart-http-rest-api

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

itrnka/ha-smart-http-rest-api
=============================

Rest API handling for `ha` framework. Package includes routes and controllers by ha framework standards. Currently is supported only JSON body in requests and responses.

v1.0.1(8y ago)16Apache-2.0PHPPHP ^7.1

Since Nov 15Pushed 8y ago1 watchersCompare

[ Source](https://github.com/itrnka/SmartHTTPRestAPI)[ Packagist](https://packagist.org/packages/itrnka/ha-smart-http-rest-api)[ Docs](https://github.com/itrnka/SmartHTTPRestAPI)[ RSS](/packages/itrnka-ha-smart-http-rest-api/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

SmartHTTPRestAPI
================

[](#smarthttprestapi)

Rest API handling for `ha` framework. Package includes routes and controllers by ha framework standards. Currently is supported only JSON body in requests and responses.

How it works
------------

[](#how-it-works)

For Rest API functionionality is required only one route, which is appended to ha router. This route is instance of `ha\SmartHTTPRestAPI\JSON\JSONRestAPIRoute` and maps requests by URL to required controllers.

Required area of functionality (product handling, category handling, ...) represent one controller, which implements `ha\SmartHTTPRestAPI\JSON\JSONRestAPIController`. All, what is needed, is add the controller into JSONRestAPIRoute route. This controller must implement `ha\SmartHTTPRestAPI\JSON\JSONRestAPIController` or must be extended from `ha\SmartHTTPRestAPI\JSON\AbstractJSONRestAPIController` (this abstract provides default required functionality for Rest API).

### interface JSONRestAPIController

[](#interface-jsonrestapicontroller)

Associated route automatically maps matched request to these methods in controllers (every controller must implement interface):

```
interface JSONRestAPIController
{
    /**
     * Handle POST request without item id in URL - save item(s) defined in request body.
     * @param string $projectName
     */
    public function createItems(string $projectName): void;

    /**
     * Handle DELETE request with item id in URL. Please do not use body in your request.
     *
     * @param string $projectName
     * @param string $itemId Item id in string format from URL
     */
    public function deleteItem(string $projectName, string $itemId): void;

    /**
     * Handle DELETE request without item id in URL. Please do not use body in your request. Specification to delete
     * must be set in $_GET.
     * @param string $projectName
     */
    public function deleteItems(string $projectName): void;

    /**
     * Handle GET request with item id in URL.
     *
     * @param string $projectName
     * @param string $itemId Item id in string format from URL
     */
    public function getItem(string $projectName, string $itemId): void;

    /**
     * Handle GET request without item id in URL (e.g. search, items list, ...). Specification and filter must be set
     * in $_GET.
     * @param string $projectName
     */
    public function getItems(string $projectName): void;

    /**
     * Handle PUT request with item id in URL (this is idempotent!), save data from request body.
     *
     * @param string $projectName
     * @param string $itemId Item id in string format from URL
     */
    public function updateItem(string $projectName, string $itemId): void;

    /**
     * Handle PUT request without item id in URL (this is idempotent!), save data from request body.
     *
     * @param string $projectName
     */
    public function updateItems(string $projectName): void;
}
```

### Example controller

[](#example-controller)

```
