Feng Office API Developer's Guide

The Feng Office API provides a powerful and simple Web Service interface to interact with your Feng Office installation. It's based on a RESTful and Stateless web service, over JSON Internet Media Type.

For the Feng Office API, we use the Lumen microframework. Check the documentation at https://lumen.laravel.com/docs/10.x

  1. OpenSSL PHP Extension
  2. PDO PHP Extension
  3. Mbstring PHP Extension
  4. Composer

Configure the .env file.

  1. Copy application\api\.env.example to application\api\.env
  2. Edit the file and replace it with your root credentials and your database name:
        DB_DATABASE=homestead
        DB_USERNAME=homestead
        DB_PASSWORD=secret 
  3. Save and close the file.

In your API installation dir (feng/application/API):

- Run composer install to install all the libraries that depend on the project.

/var/www/html/feng/application/api$ composer install

To serve the Feng Office API for development mode use:

  1. Go to your installation directory (feng)
  2. Go to API directory (feng/application/API)
  3. Run php -S localhost:8000 -t public
  4. Go to your browser and put the URL: localhost:8000
  5. If everything is OK you will see the result: “Lumen (8.3.4) (Laravel Components ^8.0)”

General test:

To test that it is in production in your browser go to your installation directory

/application/API/public/

and you will see “Lumen (8.3.4) (Laravel Components ^8.0)”.

That indicates that Feng API is working!

You will define all of the routes for your application in the routes/web.php file.

The most basic Lumen routes accept a URI and a Closure:

$router->get('foo', function () {
  return 'Hello World';
});
$router->post('foo', function () {
  //
});

Available Router Methods

The router allows you to register routes that respond to any HTTP verb:

$router->get($uri, $callback);
$router->post($uri, $callback);
$router->put($uri, $callback);
$router->patch($uri, $callback);
$router->delete($uri, $callback);
$router->options($uri, $callback);

Instead of defining your request handling logic in a single routes/web.php file, you may wish to organize this behavior using Controller classes. Controllers can group related HTTP request-handling logic into a class. Controllers are stored in the app/Http/Controllers directory.

Basic Controllers example Here is an example of a basic controller class. All Lumen controllers should extend the base controller class included with the default Lumen installation: <?PHP

namespace App\Http\Controllers;
use App\User;
class UserController extends Controller
{
  /**
  * Retrieve the user for the given ID. 
  *
  * @param int $id
  * @return Response
  */
  public function show($id) {
    return User::findOrFail($id);
  }
}

We can route to the controller action like so:

$router->get('user/{id}', 'UserController@show');

Now, when a request matches the specified route URI, the show method on the UserController class will be executed. Of course, the route parameters will also be passed to the method.

Base URI (or Endpoint) Endpoint URL:

FENGOFFICE_URL/application/API/public

If your Feng Office installation is accessible by the following url: http://example.com/feng then your API endpoint is: http://example.com/feng/application/api/public

This version counts with the following method to be invoked:

  • loginUserByToken

To invoke a remote method you need to make a request to the following URL: http://example.com/feng/application/api/public/METHOD_NAME/&exampleParam=1

Each web service request must include a GET parameter ‘auth’ containing a hash of the user password. This hash is the user token generated automatically when a user is created.