Skip to content

Simple REST and HTTP API build with Lumen Framework

Notifications You must be signed in to change notification settings

cescgie/lumen-rest-api

Repository files navigation

Lumen REST API

Table of Contents

  1. Description
  2. Installation
  3. Test
  4. Routing
  5. Helpers

Description

REST API using lumen micro framework by laravel

Installation

a. Fork or just clone this repo directly

$ git clone https://github.com/cescgie/lumen-rest-api.git

b. Create new database

c. Rename .env.example to .env and it set the config database details

  DB_CONNECTION=mysql
  DB_HOST=DATABASE_HOST
  DB_DATABASE=DATABASE_NAME
  DB_USERNAME=DATABASE_USER_NAME
  DB_PASSWORD=DATABASE_PASSWORD

c. Install the migration

$ php artisan migrate:install

d. Run the migration to create the table on the database

$ php artisan migrate

e. Seed the dummy data which stored in database/seeds

$ php artisan db:seed

Test

Now your API is ready. Its time tests the app. For testing, You can use chrome extension POSTMAN or use CURL.

  • Get all data
$ curl -I http://localhost:8000/api/article
  • Get specific article by id
$ curl -v -H "Accept:application/json" http://localhost:8000/api/article/1
  • Post new article
$ curl -i -X POST -H "Content-Type:application/json" http://localhost:8000/api/article -d '{"article_name":"Test Article","article_description":"test description"}'
  • Update specific article by id
$ curl -v -H "Content-Type:application/json" -X PUT http://localhost:8000/api/article/2 -d '{"article_name":"Test updated article","article_description":"test upadted article"}'
  • Delete specific article by id
$ curl -i -X DELETE http://localhost:8000/api/article/2

Routing

HTTP URL Description Request Response
GET /api/article Get all articles - [{"id":1,"created_at":"-0001-11-30 00:00:00","updated_at":"-0001-11-30 00:00:00","article_name":"T-Shirt","article_description":"New upcomer for this summer"},{"id":2,"created_at":"-0001-11-30 00:00:00","updated_at":"-0001-11-30 00:00:00","article_name":"Jeans","article_description":"Most searched item"}]
GET /api/article/{id} Get specific article by id - {"id":1,"created_at":"-0001-11-30 00:00:00","updated_at":"-0001-11-30 00:00:00","article_name":"T-Shirt","article_description":"New upcomer for this summer"}
POST /api/article Add new article {"article_name": "Coat", "article_description": "Latest article"} {request}
PUT /api/article/{id} Update specific article {"article_name": "Coat", "article_description": "Update latest article"} {request}
DELETE /api/article/{id} Delete specific article by id - true/false

Helpers

About

Simple REST and HTTP API build with Lumen Framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published