Fusio

Requirements

Fusio is written in PHP and requires at least version 7 and a database.

  • PHP >= 7
  • Database (supports: MySQL, PostgreSQL, MSSQL, Oracle)

Download

There are two ways of downloading Fusio:

  • Download the latest release from Github
  • Use composer and run the command composer create-project fusio/fusio

Place the scripts in the www directory of your web server. After successfully downloading Fusio, please continue with the setup process. The setup process will help configure Fusio to work properly on your server.

Setup

There are two methods of setting up Fusio for your server:

  • Manual Setup:

    Adjust the configuration file

    Open the file .env in the Fusio directory and change the key FUSIO_URL to the domain pointing to the public folder. Also insert the database credentials to the FUSIO_DB_* keys.

    Execute the installation command

    The installation script inserts the Fusio database schema into the provided database. It can be executed with the following command php bin/fusio install.

    Create administrator user

    After the installation is complete you have to create a new administrator account. Therefor you can use the following command php bin/fusio adduser. Choose as account type "Administrator".

  • Installation Script:

    To use the install script instead of the manual setup above, point your browser to public/install.php. The script will help setup Fusio and configure it to work on your server.

    Once you are done, for security reasons, remove the public/install.php script.

Now you are able to login to the backend at /fusio.

Build an API endpoint

Fusio provides a demo todo API which is ready for deployment. Take a look at the .fusio.yml file which contains the deployment configuration. The file contains several keys:

  • routes

    Describes for each route the available request methods, whether the endpoint is public or private, the available request/response schema and also the action which should be executed:

    "/todo": !include resources/routes/todo/collection.yaml
    "/todo/:todo_id": !include resources/routes/todo/entity.yaml
    
  • schema

    Contains the available request and response schema in the JSON-Schema format:

    Todo: !include resources/schema/todo/entity.json
    Todo-Collection: !include resources/schema/todo/collection.json
    Message: !include resources/schema/message.json
    
  • connection

    Provides connections to a remote service i.e. mysql or mongodb. This connection can be used inside an action. By default we use the System connection which uses the database which you have provided at the .env file. But through this it is possible to connect to multiple different external services.

    My-Connection:
      class: Fusio\Adapter\Sql\Connection\Sql
      config:
        type: "pdo_mysql"
        host: "127.0.0.1"
        username: "user"
        password: "pw"
        database: "my_db"
    

Through the command php bin/fusio deploy you can deploy the API. It is now possible to visit the API endpoint at: /todo.

Execute Migrations

The demo ToDo API uses a database to store the Todo entries. Fusio provides a migration tool to setup and evolve the database schema of your API. To setup the tables for the demo Todo API you need to execute the migrations through the following command:

php bin/fusio migration:migrate -connection=System

Please take a look at the manual for more information about the migration system.

Access a non-public API endpoint

The POST method of the todo API is not public, because of this you need an access token in order to post a request.

  • Assign the scope to your user

    In order to use a scope, the scope must be assigned to your user account. Therefor go to the user panel click on the edit button and assign the todo scope to your user.

  • Request a JWT

    Now you can obtain a JWT through a simple HTTP request to the consumer/login endpoint.

    POST /consumer/login HTTP/1.1
    Host: 127.0.0.1
    Content-Type: application/json
    
    {
      "username": "[username]",
      "password": "[password]"
    }

    Which returns a token i.e.:

    {
        "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI5N2JkNDUzYjdlMDZlOWFlMDQxNi00YmY2MWFiYjg4MDJjZmRmOWZmN2UyNDg4OTNmNzYyYmU5Njc5MGUzYTk4NDQ3MDEtYjNkYTk1MDYyNCIsImlhdCI6MTQ5MTE2NzIzNiwiZXhwIjoxNDkxMTcwODM2LCJuYW1lIjoidGVzdCJ9.T49Af5wnPIFYbPer3rOn-KV5PcN0FLcBVykUMCIAuwI"
    }
  • Request the non-public API endpoint

    Now we can use the JWT as Bearer token in the Authorization header.

    POST /todo HTTP/1.1
    Host: 127.0.0.1
    Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI5N2JkNDUzYjdlMDZlOWFlMDQxNi00YmY2MWFiYjg4MDJjZmRmOWZmN2UyNDg4OTNmNzYyYmU5Njc5MGUzYTk4NDQ3MDEtYjNkYTk1MDYyNCIsImlhdCI6MTQ5MTE2NzIzNiwiZXhwIjoxNDkxMTcwODM2LCJuYW1lIjoidGVzdCJ9.T49Af5wnPIFYbPer3rOn-KV5PcN0FLcBVykUMCIAuwI
    Content-Type: application/json
    
    {
      "title": "lorem ipsum"
    }

Summarize

This was a quick introduction how to build and consume an API with Fusio. Please take a look at the documentation section for more resources.