Description
A complete starter template for a REST API with Lumen and PHP.
It includes base implementations for using a mysql database, user registration and login via API, authentication via JWT and API routes to get data and send emails.
It’s ready to run it on your shared hosting service (See requirements).
Requirements
- PHP >= 7.1.3
- laravel/lumen-framework 5.8
- MySql database
- Composer to install the dependencies (vendor folder).
- To install dependencies on the shared hosting web space, you may need an SSH account to install and run Composer
Installation
Unzip the file. You find a sub directory “lumen-api-starter”.
Copy this folder somewhere to the wwwroot directory on your server.
Run “composer install” to install the dependencies via composer (https://getcomposer.org/).
The vendor directory will be created.
Optionally run “php artisan migrate” to initiate the database (if you can use laravel artisan)
You can now call the API. Test it with a browser (eg. http://localhost/lumen-api-starter/public/) and you will see something like “Lumen (5.8.10) (Laravel Components 5.8.*)”.
Optionally point a domain or subdomain to the sub directory “public” inside the directory “lumen-api-starter”.
How to use the API
You can now call these endpoints of the API:
- /auth/register – POST name, email and password to sign up a new User
- /auth/login – POST email and password to sign in and get an JWT token
- /auth/logout – POST to sign out the current user
- /auth/refresh – POST to refresh the JWT token
- /auth/me – POST to get your user information
- /api/items – GET a list of example items.
- /api/items/2 – GET an item by number from the list.
- /api/send/ – POST to send an example email (mail server settings required in the “.env” config file)
A full request should look like this:
- http://localhost/lumen-api-starter/public/auth/me
- http://localhost/lumen-api-starter/public/api/items
or
- http://my-domain.com/api/me
- http://my-domain.com/api/items
Customizing and Extending the API
To customize or extend the API there are several starting points:
- .env – config file to set database or mailserver
- database/migrations – migration files to initiate or update your database (optional to use laravel artisan)
- routes/web.php – to add new routes (endpoints)
- app/Http/Controllers – add a new controller file in these folder to call it in the routes/web.php
- app/Mail – add new Mailable-Classes in these folder to use new mail templates
- resources/views – add mail template files in these folder to call it in the Mailable-Class
Whats included?
- a complete starter template of a REST API that runs even on a shared hosting web space (PHP, MySql and composer required)
- a migration file to create the database structure via artisan
- Authentication via ‘auth’ prefix and AuthController
- sign up user
- sign in / sign out
- authentication with JWT (including token creation)
- if you are not authenticated you get an 401 error code
- Get example data via ‘api’ prefix and the ItemController
- get a list of items
- get a specific item by number
- Send a sample mail via ‘api’ prefix and MailController
- Laravel Mailable implementation with mail template
Reviews
There are no reviews yet.