PHPackages                             abirchler/laminas-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. [HTTP &amp; Networking](/categories/http)
4. /
5. abirchler/laminas-rest-api

ActiveLibrary[HTTP &amp; Networking](/categories/http)

abirchler/laminas-rest-api
==========================

Laminas module to build REST APIs

3.0.6(2mo ago)010.3k↓44.4%MITPHP

Since Jun 3Pushed 2mo agoCompare

[ Source](https://github.com/abirchler/laminas-rest-api)[ Packagist](https://packagist.org/packages/abirchler/laminas-rest-api)[ Docs](https://github.com/abirchler/laminas-rest-api)[ RSS](/packages/abirchler-laminas-rest-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (10)Used By (0)

RestApi module for Laminas Framework
====================================

[](#restapi-module-for-laminas-framework)

\###(*this is a removed repository from *)

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

[](#requirements)

This module has the following requirements:

- Laminas Framework.
- PHP 7 or greater.

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

[](#installation)

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

The recommended way to install composer packages is:

```
composer require abirchler/laminas-rest-api

```

Now copy this file "vendor/abirchler/laminas-rest-api/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`.

```
