DEV Community

Robertino
Robertino

Posted on • Originally published at auth0.com

Developing RESTful APIs with Lumen (A PHP Micro-framework)

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


TL;DR: In this tutorial, you will learn how to easily build a secured API with Lumen. The complete source code for this tutorial can be found here on GitHub.

Built on Laravel's core components, 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, 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.

Lumen Key Requirements

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

  • PHP: Make sure PHP >= 7.3 is installed on your machine. Furthermore, ensure that the following PHP extensions are installed. OpenSSL, PDO, and Mbstring.
  • Composer: Navigate to the Composer website and install it on your machine. A composer is needed to install Lumen's dependencies.
  • Postman: You also need to ensure that Postman, or a similar application, to test endpoints is installed.

Note: You'll need MySQL for this tutorial. Navigate to the MySQL website and install the community server edition. If you are using a Mac, I recommend following these instructions. For this tutorial, you can use MySQL straight from the terminal, but if you'd prefer a MySQL GUI, check out Sequel Pro for Mac or HeidiSQL 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...

Top comments (1)

Collapse
 
leslieeeee profile image
Leslie

Have you tried ServBay.dev?
It's a much easier tool for PHP developers, providing a user-friendly experience, especially for beginners. It supports all versions of PHP, MariaDB, PostgreSQL, as well as Redis and Memcached. You can run multiple PHP instances simultaneously and switch between them effortlessly. It also offers easy updates without the need to configure environment variables. This tool has greatly simplified my PHP development and is definitely worth trying!