Back-end application for Todolist Web application built with Laravel 5.7 and Vue.js
Switch branches/tags
Nothing to show
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.cloud Removing the french locale Dec 6, 2018
.insomnia Adding readme for insomnia Sep 5, 2018
app Updating the timezone with parse method to set due at attribute Oct 14, 2018
bootstrap Adding Laravel and docker-compose config Dec 26, 2017
config Updating deploy config Sep 9, 2018
database Upgrading files for laravel 5.7 Sep 4, 2018
lib/capistrano/tasks Updating dockerfile path for deploy Dec 6, 2018
public Adding Laravel and docker-compose config Dec 26, 2017
resources/lang Upgrading files for laravel 5.7 Sep 4, 2018
roles Forcing mysql version to 8 Oct 22, 2018
routes Adding routes to manage users Jun 13, 2018
storage Adding Laravel and docker-compose config Dec 26, 2017
tests Fixing test because a model should not be act as recently created Oct 16, 2018
.dockerignore Migrating Docker in a dedicated folder Dec 6, 2018
.editorconfig Upgrading files for laravel 5.7 Sep 4, 2018
.env.example Upgrading files for laravel 5.7 Sep 4, 2018
.env.testing Simplifying env files Aug 25, 2018
.env.travis Simplifying env files Aug 25, 2018
.gitattributes Adding Laravel and docker-compose config Dec 26, 2017
.gitignore Upgrading files for laravel 5.7 Sep 4, 2018
.php_cs Adding phpcs Dec 26, 2017
.travis.yml Upgrading mysql version to 5.7 on travis Apr 21, 2018
Capfile Adding Capistrano Apr 11, 2018
Gemfile Adding Capistrano Apr 11, 2018
Gemfile.lock Adding Capistrano Apr 11, 2018
LICENSE License for 2018 Feb 8, 2018
README.md Upgrading files for laravel 5.7 Sep 4, 2018
artisan Adding Laravel and docker-compose config Dec 26, 2017
composer.json Updating composer dependencies Dec 6, 2018
composer.lock Updating composer dependencies Dec 6, 2018
docker-compose.yml Migrating Docker in a dedicated folder Dec 6, 2018
hosts.example Using a hosts example file Jul 31, 2018
phpunit.xml Upgrading files for laravel 5.7 Sep 4, 2018
playbook.yml Removing useless user configuration Sep 9, 2018
server.php Adding Laravel and docker-compose config Dec 26, 2017

README.md

Todolist-backend Application

Build Status Donate

Backend for https://github.com/guillaumebriday/todolist-frontend-vuejs app, built for a serie of articles on my blog.

The purpose of this repository is to provide API with Laravel 5.7 and connecting JavaScript front-end frameworks like Vue.js or other clients to them.

Beside Laravel, this project uses other tools like :

Installation

Development environment requirements :

Setting up your development environment on your local machine :

$ git clone https://github.com/guillaumebriday/todolist-backend-laravel.git
$ cd todolist-backend-laravel
$ cp .env.example .env
$ docker-compose run --rm --no-deps todolist-server composer install
$ docker-compose run --rm --no-deps todolist-server php artisan key:generate
$ docker-compose run --rm --no-deps todolist-server php artisan jwt:secret
$ docker-compose up -d

Before starting

You need to run the migrations :

$ docker-compose run --rm todolist-server php artisan migrate

Seed the database :

$ docker-compose run --rm todolist-server php artisan db:seed

This will create a new user that you can use to sign in :

Email : darthvader@deathstar.ds
Password : 4nak1n

Useful commands

Running tests :

$ docker-compose run --rm todolist-server ./vendor/bin/phpunit --cache-result --order-by=defects --stop-on-defect

Running php-cs-fixer :

$ docker-compose run --rm --no-deps todolist-server ./vendor/bin/php-cs-fixer fix --config=.php_cs --verbose --dry-run --diff

Generating backup :

$ docker-compose run --rm todolist-server php artisan backup:run --only-db

Discover package

$ docker-compose run --rm --no-deps todolist-server php artisan package:discover

Generating fake data :

$ docker-compose run --rm todolist-server php artisan db:seed --class=DevDatabaseSeeder

Accessing the API

Clients can access to the REST API. API requests require authentication via JWT. You can create a new one with you credentials.

$ curl -X POST http://localhost:8000/api/v1/auth/login -d "email=your_email&password=your_password"

Then, you can use this token either as url parameter or in Authorization header :

# Url parameter
curl -X POST http://localhost:8000/api/v1/auth/me?token=your_jwt_token_here

# Authorization Header
curl -X POST --header "Authorization: Bearer your_jwt_token_here" http://localhost:8000/api/v1/auth/me

API are prefixed by api and the API version number like so v1.

Do not forget to set the X-Requested-With header to XMLHttpRequest. Otherwise, Laravel won't recognize the call as an AJAX request.

To list all the available routes for API :

$ docker-compose run --rm --no-deps todolist-server php artisan route:list

You can import my Insomnia workspace configured to work with the API : .insomnia/todolist-backend-laravel.json.

Broadcasting & WebSockets

Before using WebSockets, you need to set the PUSHER related keys in your .env file.

You could find this keys on https://pusher.com/.

You also need to set the BROADCAST_DRIVER key :

BROADCAST_DRIVER=pusher

Deploy in production

You can serve your application with nginx in production.

You can deploy this application with Ansible and Capistrano.

Copy the hosts example file and change the values to your needs :

$ cp hosts.example hosts

Setup your variables in the playbook.yml and in the config/deploy.rb files.

And then run :

$ ansible-playbook -i hosts playbook.yml

Now with Capistrano :

Before starting, change the configuration files with your informations, then run :

$ bundle install
$ cap production deploy

The first deployment might fail because mysql is not fully loaded. In this case just deploy again.

Consume the API

The application is available on https://todolist-backend.guillaumebriday.xyz/api/v1/.

You can consume the API with any client.

Some examples of projects who use this API:

Don't forget to let me know if you want to add your project to this list !

More details

More details are available on my blog post : https://guillaumebriday.fr/laravel-vuejs-faire-une-todo-list-partie-1-presentation-et-objectifs (French).

Contributing

Do not hesitate to contribute to the project by adapting or adding features ! Bug reports or pull requests are welcome.

License

This project is released under the MIT license.