gasparteixeira / api-boilerplate
Boilerplate to create a REST API with Symfony 4.2
Installs: 50
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 0
Open Issues: 1
Type:project
Requires
- php: ^7.1.3
- ext-ctype: *
- ext-iconv: *
- friendsofsymfony/rest-bundle: ^2.5
- jms/serializer-bundle: ^3.1
- lexik/jwt-authentication-bundle: ^2.6
- nelmio/api-doc-bundle: ^3.4
- sensio/framework-extra-bundle: ^5.2
- symfony/asset: 4.2.*
- symfony/console: 4.2.*
- symfony/dotenv: 4.2.*
- symfony/flex: ^1.1
- symfony/framework-bundle: 4.2.*
- symfony/orm-pack: ^1.0
- symfony/routing: 4.2.*
- symfony/security: 4.2.*
- symfony/security-bundle: 4.2.*
- symfony/security-core: 4.2.*
- symfony/security-http: 4.2.*
- symfony/swiftmailer-bundle: ^3.2
- symfony/templating: 4.2.*
- symfony/translation: 4.2.*
- symfony/yaml: 4.2.*
Requires (Dev)
- doctrine/doctrine-fixtures-bundle: ^3.1@dev
- guzzlehttp/guzzle: ^6.3
- symfony/browser-kit: 4.2.*
- symfony/debug-pack: ^1.0
- symfony/maker-bundle: ^1.11
- symfony/phpunit-bridge: 4.2.*
- symfony/web-server-bundle: 4.2.*
Conflicts
This package is auto-updated.
Last update: 2025-03-06 16:33:40 UTC
README
This project is to help people to start a fast API
Requirements
PHP, MySQL, Git, Composer, openssl
Symfony has a build-in web server you do not need Apache or Ngnx to run this project. Thanks Symfony :)
Install with composer
Change (my-project-name) with the name of your project
$ composer create-project gasparteixeira/api-boilerplate my-project-name
Check it out
cd my-project-name
$ php bin/console cache:clear
Environment
- Open the file .env and configure your database connection (user, password and database_name)
DATABASE_URL=mysql://user:password@127.0.0.1:3306/database_name
- For security reasons, change this password
JWT_PASSPHRASE=boilerplate #change this password name and use the same password when you are generating the ssh keys
- Basic Auth, change username and password
// config/services.yml parameters: app_username: boilerplate app_password: S3cr37W0rd
Generate SSH keys
use the same password you defined in .env, when asked for it
$ mkdir -p config/jwt # For Symfony3+, no need of the -p option
$ openssl genrsa -out config/jwt/private.pem -aes256 4096
$ openssl rsa -pubout -in config/jwt/private.pem -out config/jwt/public.pem
Creating database
execute the command line to create your database
$ php bin/console doctrine:database:create
make migrations
$ php bin/console make:migration
lets commit the migration (it will create a table called user)
$ php bin/console doctrine:migrations:migrate
Load fixtures
add an user (src/DataFixtures/UserFixtures) to make the test
$ php bin/console doctrine:fixtures:load
Running
$ php bin/console server:run
Testing
You can test it using Postman or through the terminal with curl using the username and password you defined in config\services.yml
curl -X POST -H "Authorization: Basic $(echo -n api@boilerplate.com:12345 | base64)" http://localhost:8000/api/token
Response must start like:
{ "token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE1NTE4MjAwNzEsImVtYWlsIjo.. " }
PHPUnit
$ php bin/phpunit
API documentation
Go to http://localhost:8000/api/doc More stuff check out https://symfony.com