Simple RESTfull API with Lumen – Laravel Microframework

Lumen is Laravel micro-framework that build for small web application and handle some micro-services. Nowadays people love to use Lumen for build fast API for their application.

Installing Lumen

if you have installed lumen installer using composer, you just need to type:

lumen new api


api : directory of project that you want to start build

or you can install lumen via composer create-project:

composer create-project laravel/lumen --prefer-dist api

Check all your artisan command by type:

php artisan

Run lumen on your local server

php artisan serve


Screen Shot 2015-12-29 at 9.12.45 PM

For full documentation you can read here.

when the package downloaded, you can start modify .env file from rename .env.example file. Fill the database detail setting to connect with your database in your local machine.


In the api/bootstrap/app.php uncommenting this following line:



this step is to create table in your database. In this example, there are article table that consist of 6 column.
id (auto increment), title varchar, content text, author varchar, update_at timestamp, and created_at timestamp.

php artisan make:migration --create=article create_article_table


it will create migration file under /database/migration . Edit xxx_create_article_table.php file

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateArticleTable extends Migration {
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('article', function(Blueprint $table)
     * Reverse the migrations.
     * @return void
    public function down()
save and run :

php artisan migrate

you are now success to create article table in your database.


create article model under App/Article.php
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
     protected $fillable = ['title', 'content', 'author'];



create article controller under app/Http/Controllers/ArticleController.php

namespace App\Http\Controllers;
use App\Book;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ArticleController extends Controller{
    public function index(){
        $Articles  = Article::all();
        return response()->json($Articles);
    public function getArticle($id){
        $Article  = Article::find($id);
        return response()->json($Article);
    public function createArticle(Request $request){
        $Article =Article::create($request->all());
        return response()->json($Article);
    public function deleteArticle($id){
        $Article  =Article::find($id);
        return response()->json('success');
    public function updateArticle(Request $request,$id){
        $Article  =Article::find($id);
        $Article->title = $request->input('title');
        $Article->content = $request->input('content');
        $Article->author = $request->input('author');
        return response()->json($Article);

Add your routing under app/Http/routes.php

$app->get('/', function () use ($app) {
return $app->welcome();
$app->group(['prefix' => 'api/v1','namespace' => 'App\Http\Controllers'], function($app){

Run and test your api project on your local server using curl or i recomend you to use postman in chrome. Try in many method like get, post, put and delete.

example to get all article just type http://localhost/api/v1/article and set get method in your post man, it will return all article data in json format if you have already insert data before.

don’t forget to put id of article, if you want to request get 1 article, or update (put) and delete article ( single article )

if you want to add new article, simply you just need to fill the parameter title,content and author data that you want to add into database.

Error : \system\codeigniter\Common.php on line 130 & 136 in Code Igniter

Deprecated: Assigning the return value of new by reference is deprecated in C:\web\site\system\codeigniter\Common.php on line 130

Deprecated: Assigning the return value of new by reference is deprecated in C:\web\site\system\codeigniter\Common.php on line 136

if you got error like that , after uploading and try to load in your hosting . its may be complicated with PHP version

How to solve it ?

here is the step :

A. remove by condition set_magic_quotes_runtime

file: codeigniter/CodeIgniter.php (line: 60)

set_magic_quotes_runtime(0); // Kill magic quotes 

B. remove all new object by reference, change ‘=&’ to ‘=’

from: $objects[$class] =& new $name();
became: $objects[$class] = new $name();

file: codeigniter/Common.php   (line: 130)
file: codeigniter/Common.php   (line: 136)
file: libraries/Loader.php   (line: 255)
file: database/DB.php       (line: 133)

$objects[$class] = new $name(); 

see: = new
C. since hyphen ‘-’ became special character in php 5.3, change this way:

file: config/config.php     (line: 153)


$config['permitted_uri_chars'] = 'a-z ~%.:_\-'; 


$config['permitted_uri_chars'] = '~%.:_\-'; 

file: libraries/URI.php     (line: 189)


if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) 


if ( !
preg_match("|^[\w".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) 

! preg_match(”|^[\w

 Try to load your website again 🙂