My name is Hasan Hasibul. I’m a senior Software Engineer with the company, Skipper, (a group hotel booking platform). Over the last five years, I have been developing REST API. During that time I have read many books, articles, and magazine to follow REST API best practices and principles. I think now it’s time for me to share what I have learned so far.
I’ve used both PHP and NodeJs to build REST API. Also, used Laravel, Symfony, ExpressJs, and Lumen. I love building stuff with Laravel. But for building REST API Lumen is the perfect PHP solution. In this series of articles, I’ll be using Lumen(5.4) for building blazing fast REST API.
You can see the finished version of this series in Github.
Summary Of this Part
Installing Composer, Lumen, setting up the local development server with Laravel Homestead. If you are already familiar with installing Lumen and Homestead you can skip this part.
There are two ways to install Lumen: via Lumen installer and composer. Before installing Lumen make sure you have composer installed on your machine. You can download composer from here: https://getcomposer.org/download/
Via Lumen Installer
First, download the Lumen installer using Composer
composer global require "laravel/lumen-installer"
Once installed the lumen new command will create a fresh new Lumen project for you. Using that command let’s create a new project name RestApi.
lumen new RestApi
Or Via Composer Create-Project:
composer create-project --prefer-dist laravel/laravel RestApi
You can use either one of the above commands to install Lumen. Here are the details about installing Lumen: https://lumen.laravel.com/docs/5.4
Local Development Server With Homestead
For this project, we’re going to use Larevel Homestead for local development. Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine. If you want you can use PHP local server or valet. The installing guide for Homestead can be found here: Homestead.
After installing Homestead we need to modify the host file that way we can use a domain name. Run this command in (Mac)
sudo vi /etc/hosts
Then add this line:
Now, we can access the app visiting this url http://restapi.app/
In this part, we’ve installed Lumen and setup development server using Homestead. For the next part, we are going to dig into the actual coding.