Simple JSON API which is build on top of Symfony framework.
- What is this?
- Table of contents
- Main points
- Requirements
- Installation
- Development
- Useful resources + tips
- Contributing & issues & questions
- Authors
- LICENSE
- This is just an API, nothing else
- Only JSON responses from API
- Easy REST API configuration and customization, see examples here and here
- JWT authentication
- API documentation
- Configuration for each environment and/or developer
- Authentication via JWT
- CORS support
- "Automatic" API doc generation (Swagger)
- Database connection (Doctrine dbal + orm)
- Console tools (dbal, migrations, orm)
- Docker support
- Logger (monolog)
- TravisCI tests
- Make tests, every endpoint
- Docs - Generic
- Docs - New api endpoint
- Docs - New REST service
- And everything else...
- PHP 7.0+
- Apache / nginx see configuration information here
- Use your favorite IDE and get checkout from git OR just use command
git clone https://github.com/tarlepp/symfony-backend.git - Open terminal, go to folder where you make that checkout and run following commands
JWT SSH keys generation
$ openssl genrsa -out app/var/jwt/private.pem -aes256 4096
$ openssl rsa -pubout -in app/var/jwt/private.pem -out app/var/jwt/public.pemFetch all dependencies
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar installNote that this will also ask you some environment settings; db, mail, secrets, jwt, etc.
You need to check that your environment is ready to use this application in CLI and WEB mode.
First step is to make sure that var directory permissions are set right. Instructions
for this can be found here.
Open terminal and go to project root directory and run following command.
$ ./bin/symfony_requirementsCheck the output from your console.
Open terminal and go to project root directory and run following command to start standalone server.
$ ./bin/console server:runOpen your favorite browser with http://127.0.0.1:8000/config.php url and check it for any errors.
And if you get just blank page double check your permissions.
To get JWT authorization headers to work correctly you need to make sure that your Apache config has mod_rewrite enabled. This you can do with following command:
$ sudo a2enmod rewriteApplication will ask your configuration settings when you first time run php composer.phar install command.
All those parameters that you should change are in /app/config/parameters.yml file, so just open that and
made necessary changes to it.
If you want to answer those parameter values again, you can just delete /app/config/parameters.yml file and
then run php composer.phar update command.
At start you have just empty database which you have configured in previous topic. To initialize your database just run following command:
$ ./bin/console doctrine:schema:update --forceFirst you need to create user groups for your users. You can create new user groups with following command:
$ ./bin/console user:createGroupAnd after that you can create new users with following command:
$ ./bin/console user:createIt's highly recommended that you use this tool while doing actual development to application. PHP Code Sniffer is added to project dev dependencies, so all you need to do is just configure it to your favorite IDE. So the phpcs command is available via following example command.
$ ./vendor/bin/phpcs -iIf you're using PhpStorm following links will help you to get things rolling.
Generally you will need to generate migration files from each database change that you're doing. Easiest way to handle these are just following workflow:
- Made your changes to Entity (
/src/App/Entity/) - Run diff command to create new migration file;
$ ./bin/console doctrine:migrations:diffWith this you won't need to write those migration files by yourself, just let doctrine handle those - although remember to really look what those generated migration files really contains...
Project contains bunch of tests (unit, functional, integration, etc.) which you can run simply by following commands:
# PHPUnit
$ ./vendor/bin/phpunit
# PHPSpec
$ ./vendor/bin/phpspec runOr you could easily configure your IDE to run these for you.
Add following lines to your xdebug.ini file to get XDebug work:
xdebug.remote_enable=on
xdebug.remote_autostart=off
- Symfony Development using PhpStorm - Guide to configure your PhpStorm for Symfony development
- PHP Annotations plugin for PhpStorm - PhpStorm plugin to make annotations really work
- Php Inspections (EA Extended) for IntelliJ IDEA - Static Code Analysis tool for PHP
- Use 1.1-dev version of composer, so that you can use
php composer.phar outdatedcommand to check package versions
Please see the CONTRIBUTING.md file for guidelines.
Copyright (c) 2017 Tarmo Leppänen
