This is a simple example of API Methods in Laravel/Lumen
- Run the composer install command to setup the Laravel/Lumen environment
composer install
- Configure the database with contact table. You can use the Laravel Artisan or import the "database.sql" file in the project root folder.
php artisan migrate
- Copy the .env.example on root folder if not exists .env file. In that file, you will need change the database configuration
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=simple_contact_api
DB_USERNAME=root
DB_PASSWORD=
- Create your vhost to the project directory
<VirtualHost *:80>
DocumentRoot /var/www/htdocs/REPOSITORY_NAME
ServerName simple-contact-api.local
ErrorLog "/var/www/htdocs/REPOSITORY_NAME/contato_local-error.log"
CustomLog "/var/www/htdocs/REPOSITORY_NAME/contato_local-access.log" common
</VirtualHost>
- Dont forget to redirect your hosts file to listening your REPOSITORY_NAME
In this example, we will just create the contact methods.
Get a single contact on database.
- Method: GET
- Path: /contact/{id}
Param(s)
- {id} : Obrigatório The contact id on database. Example
curl -X GET YOUR_SERVER_NAME/contact/1
Create a new one contact on database.
- Method: POST
- Path: /contact
Example
curl -X POST \
-d "name=Brand New Contact&email=email@contact.me&description=Description from the contact" \
YOUR_SERVER_NAME/contact
Create a new one contact on database.
- Method: PUT
- Path: /contact/{id}
Param(s)
- {id} : Obrigatório The contact id on database. Example
curl -X PUT \
-d "name=Change my name&email=change_email@contact.me&description=Description from the contact" \
YOUR_SERVER_NAME/contact/1
Create a new one contact on database.
- Method: DELETE
- Path: /contact/{id}
Param(s)
- {id} : Obrigatório The contact id on database. Example
curl -X PUT \
-d "name=Change my name&email=change_email@contact.me&description=Description from the contact" \
YOUR_SERVER_NAME/contact/1
Documentation for the framework can be found on the Lumen website.
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell at taylor@laravel.com. All security vulnerabilities will be promptly addressed.
The Lumen framework is open-sourced software licensed under the MIT license