Skip to content

app-generator/api-server-laravel

Repository files navigation

Simple Laravel API Server with JWT authentication, and SQLite persistence - Provided by AppSeed App Generator and UPDIVISION.


Features:

  • API Definition - the unified API structure implemented by this server
  • Simple, intuitive codebase - can be extended with ease.
  • Stack: PHP 7.4+ / Laravel / Doctrine
  • JWT Authentication

Can be used with other React Starters for a complete Full-Stack experience:

React Node JS Berry React Node Soft Dashboard React Node Datta Able
React Node JS Berry React Node Soft Dashboard React Node Datta Able

Laravel API Server - Open-source Nodejs Starter provided by AppSeed.


Requirements

  • PHP 7.4+
  • Extensions (check the #Troubleshooting section for installation info)
    • php-xml
    • php7.4-sqlite

How to use the code

Step #1 - Clone the project

$ git clone https://github.com/app-generator/api-server-laravel.git
$ cd api-server-laravel

Step #2 - Install dependencies

$ composer install
$ cp .env.example .env 
$ php artisan key:generate

Step #3 - Generate a secret key used by JWT Authentication Flow

$ php artisan jwt:secret

Step #4 - Set up the database

$ touch database/database.sqlite
$ php artisan migrate

Step #5 - Start the server

$ php -S localhost:5000 server.php

Troubleshooting

To have a successful compilation of this product, make sure you have the following PHP extensions installed and enabled:

  • php-xml - required by Php-Unit
  • php7.4-sqlite - The SQLite driver required by Laravel ORM
$ # Php XML - required by Php Unit
$ sudo apt install php-xml php-cli php-mbstring php7.4-sqlite

Codebase Structure

< ROOT >
     | 
     |-- app/          # Implements APP Bussiness Logic                    
     |-- config/       # Configuration
     |-- public/       # Public folder                         
     |-- routes/       # Application ROutes                        
     |-- tests/        # Tests                              
     | 
     |-- server.php    # API Entry Point
     |-- .env          # Specify the ENV variables
     |                        
     |-- ************************************************************************

API

For a fast set up, use this POSTMAN file: api_sample

Register - api/users/register

POST api/users/register
Content-Type: application/json

{
    "username":"test",
    "password":"pass", 
    "email":"test@appseed.us"
}

Login - api/users/login

POST /api/users/login
Content-Type: application/json

{
    "password":"pass", 
    "email":"test@appseed.us"
}

Logout - api/users/logout

POST api/users/logout
Content-Type: application/json
authorization: JWT_TOKEN (returned by Login request)

{
    "token":"JWT_TOKEN"
}


Laravel API Server - provided by AppSeed App Generator