Developing RESTful APIs with Lumen (A PHP Micro-framework)
Tags: webdev, programming, php
Published: 2022-02-17 14:06:23

### Learn how to build a secured Lumen API server using Auth0.


### <br>

**TL;DR:** In this tutorial, you will learn how to easily build a secured API with [Lumen](https://lumen.laravel.com/). The complete source code for this tutorial can be found here on [GitHub](https://github.com/yemiwebby/lumen-api-auth0).

Built on Laravel's [core components](https://github.com/illuminate), Lumen is able to provide speed without sacrificing any of the goodies we love about Laravel - clean and concise syntax; flexibility, and out-of-the-box support for just about anything you can think of. The scalability of an application is also not affected as Lumen is built to upgrade directly to Laravel painlessly should the application needs to outgrow Lumen's offerings.

## Features Overview

These are some of the built-in features of Lumen:

- **Routing** is provided out of the box in Lumen. This includes basic routing, routing parameters, named routes, and route groups such as middleware.
- **Authentication** does not support the session state. However, incoming requests are authenticated via stateless mechanisms such as tokens.
- **Caching** is implemented the same as in Laravel. Cache drivers such as *Database*, *Memcached*, and *Redis* are supported. For example, you can install the `illuminate/redis` package via Composer to use a Redis cache with Lumen.
- **Errors and Logging** are implemented via the [Monolog library](https://github.com/Seldaek/monolog), which provides support for various log handlers.
- **Queuing** services are similar to the ones offered by Laravel. A unified API is provided across a variety of different queue back-ends.
- **Events** provide a simple observer implementation that allows you to subscribe and listen for events in your application.
- **Bootstrapping** processes are located in a [single file](https://github.com/laravel/lumen/blob/master/bootstrap/app.php).

## Lumen Key Requirements

To use Lumen, you need to have the following tools installed on your machine:

- **PHP**: Make sure [PHP >= 7.3](http://php.net/manual/en/install.php) is installed on your machine. Furthermore, ensure that the following PHP extensions are installed. [OpenSSL](https://www.php.net/manual/en/openssl.installation.php), [PDO](https://www.php.net/manual/en/pdo.installation.php), and [Mbstring](https://www.php.net/manual/en/mbstring.installation.php).
- **Composer**: Navigate to the [Composer website](https://getcomposer.org/) and install it on your machine. A composer is needed to install Lumen's dependencies.
- **Postman**: You also need to ensure that [Postman](https://www.getpostman.com/), or a similar application, to test endpoints is installed.

> Note: You'll need MySQL for this tutorial. Navigate to the [MySQL](https://www.mysql.com/) website and install the community server edition. If you are using a Mac, I recommend following [these instructions](https://flaviocopes.com/mysql-how-to-install/). For this tutorial, you can use MySQL straight from the terminal, but if you'd prefer a MySQL GUI, check out [Sequel Pro](https://sequelpro.com/) for Mac or [HeidiSQL](https://www.heidisql.com/) for Windows.

## Building a Fast Authors API Rapidly With Lumen

At Auth0, we have many technical writers, otherwise known as authors. A directive has been given to developing an app to manage Auth0 authors. The front-end app will be built with ReactJS. However, it needs to pull data from a source and also push to it. Yes, we need an API!

An author will have the following attributes:

- Name
- Email address
- Link to Twitter profile
- Link to GitHub profile
- Location
- Title of the latest article published by the author


[Read more...](https://auth0.com/blog/developing-restful-apis-with-lumen-a-php-micro-framework/?utm_source=content_synd&utm_medium=sc&utm_campaign=php)