PHPackages                             itdelivery/zend-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. [API Development](/categories/api)
4. /
5. itdelivery/zend-api

ActiveLibrary[API Development](/categories/api)

itdelivery/zend-api
===================

API

094PHPCI failing

Since Jun 27Pushed 5y ago1 watchersCompare

[ Source](https://github.com/fmangat/itdelivery)[ Packagist](https://packagist.org/packages/itdelivery/zend-api)[ RSS](/packages/itdelivery-zend-api/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

RestApi module for Zend Framework 3
===================================

[](#restapi-module-for-zend-framework-3)

Requirements
------------

[](#requirements)

This module has the following requirements:

- Zend Framework 3 or greater.
- PHP 7 or greater.

Installation
------------

[](#installation)

You can install this module into your Zend Framework application using [composer](http://getcomposer.org).

The recommended way to install composer packages is:

```
composer require itdelivery/zend-api

```

Now copy this file "vender/itdelivery/ZendAPI/config/restapi.global.php" and paste to root "config/autoload/restapi.global.php"

If you do not setup at the time of package installation then add this 'RestApi' to modules.config.php file.

```
return [
    ....
    //add this if not available
    'RestApi'
];
```

Usage
-----

[](#usage)

You just need to create your API related controller and extend it to `ApiController` instead of default `AbstractActionController`. You just need to set you results in `apiResponse` variable and your response code in `httpStatusCode` variable and return $this-&gt;createResponse(). For example,

```
namespace Application\Controller;

use RestApi\Controller\ApiController;

/**
 * Foo Controller
 */
class FooController extends ApiController
{

    /**
     * bar method
     *
     */
    public function barAction()
    {
        // your action logic

        // Set the HTTP status code. By default, it is set to 200
        $this->httpStatusCode = 200;

        // Set the response
        $this->apiResponse['you_response'] = 'your response data';

        return $this->createResponse();
    }
}
```

You can define your logic in your action function as per your need. For above example, you will get following response in `json` format,

```
{"status":"OK","result":{"you_response":"your response data"}}
```

The URL for above example will be `http://yourdomain.com/foo/bar`. You can customize it by setting the your module.config.php as following.

```
'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\FooController::class,
                        'action' => 'bar',
                        'isAuthorizationRequired' => true // set true if this api Required JWT Authorization.
                    ],
                ],
            ],
        ],
    ],
```

Simple :)

Configurations
--------------

[](#configurations)

This module provides several configurations related to Response, Request and `JWT` authentication. The default configurations are in previously you copy and past file this restapi.global.php have configurations`.

```
