Laravel create REST API with Fusio

Christoph Kappestein
2 min readAug 17, 2022

--

In this post I will explain how to integrate a REST API build with Fusio into an existing Laravel app. To dive directly into the code please checkout our Laravel sample app which contains the complete Fusio integration.

Introduction

At first I like to give a short introduction to Laravel and Fusio. Laravel is a popular PHP framework which helps to build web applications. Fusio is an open source API management system which helps to build and manage REST APIs.

You may ask yourself why we need a separate tool like Fusio to build an API instead of using Laravel directly. It always depends on your use case but Fusio is a dedicated tool to build APIs which already covers many topics like:

  • OpenAPI generation
  • Subscription support
  • Rate limiting
  • OAuth2 authorization
  • Monetization
  • SDK generation

which you otherwise need to build with Laravel. If you want to create a complete API product we recommend to checkout Fusio.

Integration

So lets take a look and see how the integration works. From a high level view we have the following workflow:

Every time a user registers at your Laravel-App we create a Fusio user in the background s. app/Listeners/LogRegistered.php. The client uses the credentials from the configuration so make sure that those credentials have the fitting permissions to create a user.

If a user authenticates at your Laravel-App we obtain an Access-Token from our Fusio instance in the background and save the obtained Access-Token in the session s. app/Listeners/LogLogin.php For further calls to the API we use then this Access-Token to work on behalf of the user.

As example we have implemented an Apps page at the dashboard where the user can manage and control all apps. If a user creates a new app he obtains an App-Key/Secret which he can use to access your API build with Fusio. It is also possible to implement all other features of Fusio into your Laravel app by using our SDK.

Summary

This was a short explanation how you can integrate Fusio into your Laravel app. If you want to learn more about Fusio please take a look at our website or checkout the repository.

In the past we have also published an article which explains, how to use Eloquent directly in Fusio. Also please let us know if you have any thoughts or questions regarding the integration, we think that Fusio and Laravel is a great match and it helps you to use the right tool for the right job.

--

--

Christoph Kappestein
Christoph Kappestein

Written by Christoph Kappestein

I am a developer in the API space, currently working on Fusio an open source API management platform

No responses yet