All Projects → munza → lumen-api-starter

munza / lumen-api-starter

Licence: MIT license
A starter project to develop API with Lumen 8.*

Programming Languages

PHP
23972 projects - #3 most used programming language
Makefile
30231 projects
Dockerfile
14818 projects
shell
77523 projects

Projects that are alternatives of or similar to lumen-api-starter

Lumen Api Oauth
A RESTful API based on Lumen micro-framework with OAuth2.
Stars: ✭ 73 (+73.81%)
Mutual labels:  lumen, restful-api
response
Response HTTP package for Simfony, Laravel, Lumen and PHP 7 with standard REST API
Stars: ✭ 14 (-66.67%)
Mutual labels:  lumen, restful-api
Lumen Api Starter
Lumen 8 基础上扩展出的API 启动项目,精心设计的目录结构,规范统一的响应数据格式,Repository 模式架构的最佳实践。
Stars: ✭ 197 (+369.05%)
Mutual labels:  lumen, restful-api
lumen-start-app
Boilerplate for laravel/lumen framework https://github.com/laravel/lumen, ready to be used with https://github.com/ionghitun/react-start-app or https://github.com/ionghitun/next-start-app
Stars: ✭ 41 (-2.38%)
Mutual labels:  lumen, lumen-framework
lumen-realworld-example-app
Exemplary real world backend API built with Lumen + MongoDB
Stars: ✭ 50 (+19.05%)
Mutual labels:  lumen, lumen-framework
SugarRestSharp
SugarRestSharp is a .NET C# SugarCRM/SuiteCRM Rest API Client. It is .NET C# Wrapper for the SugarCRM/SuiteCRM REST API Client.
Stars: ✭ 29 (-30.95%)
Mutual labels:  restful-api
akaash-rest-api
Akaash: A restful API template built with PHP driven by flight micro-framework
Stars: ✭ 17 (-59.52%)
Mutual labels:  restful-api
Library
Online Library Management. User can search, check in, checkout book. System adds fines automatically if the book is not checked in by due date
Stars: ✭ 27 (-35.71%)
Mutual labels:  restful-api
kite-server
“上应小风筝”小程序 API 代码和文档, 基于 Rust 语言的 poem 框架编写.
Stars: ✭ 19 (-54.76%)
Mutual labels:  restful-api
lumen-file-manager
File manager module for the Lumen PHP framework.
Stars: ✭ 40 (-4.76%)
Mutual labels:  lumen
questionnaire online
springboot+mybatis在线问卷系统
Stars: ✭ 147 (+250%)
Mutual labels:  restful-api
SimpleGlip
A simple Glip client with RESTful API
Stars: ✭ 20 (-52.38%)
Mutual labels:  restful-api
FullStack-Angular-SpringBoot
Customer Relationship Managment [Full-stack Web Development using Angular & SpringBoot (RestFull API)]
Stars: ✭ 48 (+14.29%)
Mutual labels:  restful-api
shadowsocks-restful-api
Secure, reliable, standard restful api for managing shadowsocks-libev
Stars: ✭ 72 (+71.43%)
Mutual labels:  restful-api
wgrest
WireGuard REST API
Stars: ✭ 92 (+119.05%)
Mutual labels:  restful-api
roundup
un-official mirror of http://hg.code.sf.net/p/roundup/code -- used for CI. Please visit https://issues.roundup-tracker.org for finding starter issues or log new issues.
Stars: ✭ 20 (-52.38%)
Mutual labels:  restful-api
alipay
laravel lumen alipay 最简单,最安全,无验签,支付宝转账支付
Stars: ✭ 18 (-57.14%)
Mutual labels:  lumen
Laravel-Auto-Hard-Deleter
Laravel and Lumen Auto Hard Deleter
Stars: ✭ 34 (-19.05%)
Mutual labels:  lumen
spring-interview-questions
500+ Spring-Boot Interview Questions
Stars: ✭ 269 (+540.48%)
Mutual labels:  restful-api
CourseCake
By serving course 📚 data that is more "edible" 🍰 for developers, we hope CourseCake offers a smooth approach to build useful tools for students.
Stars: ✭ 21 (-50%)
Mutual labels:  restful-api

Lumen API Starter

A starter template to develop API with Lumen 8.

This repo will not be maintained anymore because 👇

Note: In the years since releasing Lumen, PHP has made a variety of wonderful performance improvements. For this reason, along with the availability of Laravel Octane, we no longer recommend that you begin new projects with Lumen. Instead, we recommend always beginning new projects with Laravel.

https://lumen.laravel.com/docs/9.x

Included Packages

Installation

  • Clone the Repo:
    • git clone [email protected]:munza/lumen-api-starter.git
    • git clone https://github.com/munza/lumen-api-starter.git
  • cd lumen-api-starter
  • SSH into the Docker container with make ssh and run the following.
    • composer create-project
    • php artisan key:generate
    • php artisan jwt:secret
    • php artisan migrate
  • Exit from Docker container with CTRL+C or exit.
  • Rename docker-compose.local.yaml to docker-compose.overridee.yaml
  • Start the local development server with make up.
  • Run tests with make dev-test.
  • Run make to see available commands.

Create new user

  • make ssh
  • php artisan ti
  • App\Models\User::factory()->create(['email' => '[email protected]', 'password' => 'password'])

Configuration

  • Edit .env file for environment variables.
  • Edit the files in config directory for application configuration.

Usage

Always ssh into Docker container app by running make ssh before executing any artisan commands.

Add a new resource endpoint

  • Add endpoint in routes/web.php.

    $router->group(['middleware' => 'auth:api'], function ($router) {
        $app->get('/users', 'UserController@index');
    });
  • Add controller with php artisan make:controller {name} command

  • Add model at php artisan make:model {name}. You can use -m flag to add migration file and -f flag for factory file.

  • Add service at app directory.

    <?php
    
    namespace App;
    
    class Accounts
    {
        // Add service methods.
    }
  • Load the service in controller.

    <?php
    
    namespace App\Http\Controllers;
    
    use App\Accounts;
    
    class UserController extends Controller
    {
        /**
         * Controller constructor.
         *
         * @param  \App\Accounts  $accounts
         */
        public function __construct(Accounts $accounts)
        {
            $this->accounts = $accounts;
        }
    
        // Add controller methods.
    }

    You can also use Facade for the services.

  • Add transformers at app/Transformers directory or use the command php artisan make:transformer {name}.

    <?php
    
    namespace App\Transformers;
    
    use App\User;
    use League\Fractal\TransformerAbstract;
    
    class UserTransformer extends TransformerAbstract
    {
        /**
         * Transform object to array.
         *
         * @param  \App\User $user
         * @return array
         */
        public function transform(User $user): array
        {
            return [
                'id' => (int) $user->id,
                'email' => (string) $user->email,
            ];
        }
    }
  • Render JSON in controllers

    <?php
    
    namespace App\Http\Controllers;
    
    use App\Accounts;
    use Illuminate\Http\JsonResponse;
    use Illuminate\Http\Request;
    use Illuminate\Http\Response;
    
    class UserController extends Controller
    {
        /**
         * Controller constructor.
         *
         * @param  \App\Accounts  $accounts
         */
        public function __construct(Accounts $accounts)
        {
            $this->accounts = $accounts;
        }
    
        /**
         * List of all users.
         *
         * @return \Illuminate\Http\JsonResponse
         */
        public function index(): JsonResponse
        {
            $users = $this->accounts->getUsersWithPagination($request);
    
            return response()->json($users, Response::HTTP_OK);
        }
    }
  • Exception message, status code and details can be displayed by declaring these as methods in an exception class.

    <?php
    
    namespace App\Exceptions;
    
    use Symfony\Component\HttpKernel\Exception\HttpException;
    
    class CustomException extends HttpException
    {
        public function getMessage(): string
        {
            return 'Custom message';
        }
    
        public function getStatusCode(): int
        {
            return 500;
        }
    
        public function getDetails(): ?array
        {
            return [];
        }
    }

Authentication

  • Create Bearer Token
curl --request POST 'http://127.0.0.1:8000/auth' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "email": "[email protected]",
        "password": "password"
    }'

Example Bearer Token -

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjE6ODAwMFwvYXV0aCIsImlhdCI6MTYzNDI2MTQzNSwiZXhwIjoxNjM0MjY1MDM1LCJuYmYiOjE2MzQyNjE0MzUsImp0aSI6IlVzVm1PZk52dTBrOTZFYk4iLCJzdWIiOjEsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjcifQ.xjvzoFCkxlB_k2z0R0zkeatDDRU0hAbRFMETAEZBsss

Bearer Token need to passed in the request header as

Authorization: Bearer <token>
  • Get Current User
curl --request GET 'http://127.0.0.1:8000/auth' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjE6ODAwMFwvYXV0aCIsImlhdCI6MTYzNDI2MTQzNSwiZXhwIjoxNjM0MjY1MDM1LCJuYmYiOjE2MzQyNjE0MzUsImp0aSI6IlVzVm1PZk52dTBrOTZFYk4iLCJzdWIiOjEsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjcifQ.xjvzoFCkxlB_k2z0R0zkeatDDRU0hAbRFMETAEZBsss'

Using CORS

Please check fruitcake/laravel-cors in Github for the usage details.

Todo

  • Move all the extended features inside a package.

Issues

Please create an issue if you find any bug or error.

Contribution

Feel free to make a pull request if you want to add anything.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].