ftm-pm / symfony-api
The SymfonyApi is configured bundles for creating a REST API.
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^7.1.3
- ext-iconv: *
- api-platform/core: ^2.1
- doctrine/annotations: ^1.6
- gedmo/doctrine-extensions: ^2.4
- gesdinet/jwt-refresh-token-bundle: ^0.3.2
- gfreeau/get-jwt-bundle: 2.0.x-dev
- guzzlehttp/guzzle: ^6.3
- lexik/jwt-authentication-bundle: ^2.4
- nelmio/cors-bundle: ^1.5
- symfony/asset: ^4.0
- symfony/console: ^4.0
- symfony/expression-language: ^4.0
- symfony/flex: ^1.0
- symfony/framework-bundle: ^4.0
- symfony/lts: ^4@dev
- symfony/maker-bundle: ^1.0
- symfony/orm-pack: ^1.0
- symfony/swiftmailer-bundle: ^3.2
- symfony/twig-bundle: ^4.0
- symfony/validator: ^4.0
- symfony/yaml: ^4.0
Requires (Dev)
- symfony/dotenv: ^4.0
- symfony/var-dumper: ^4.0
Conflicts
Replaces
This package is not auto-updated.
Last update: 2020-01-24 17:41:44 UTC
README
The SymfonyApi is configured bundles for creating a REST API.
Russian documentation here.
Setup
The SymfonyApi is a symfony/skeleton application with bundles:
Installation
Run the Composer command to create a new project
composer create-project ftm-pm/symfony-api my-project
Configuration
After installing, you need to set environment variables. You can see variables in the .env file.
Next step, run command to update database.
php bin/console d:s:u --force
In SymfonyApi, authorization was developed using JWT. You can see documentation here.
For create a new user, you can use any REST client. You should send a new request to http://my-project/api/register with parameters:
{ "username": "johndoe", "password": "test", "email": "johndoe@example.com" }
or using curl
curl -X POST http://my-project/api/register -d username=johndoe -d password=test -d email=johndoe@example.com
After the confirmation email, get token. Send a new request to http://my-project/api/token
:
{ "username": "johndoe", "password": "test" }
or using curl
curl -X POST http://my-project/api/token -d username=johndoe -d password=test
The SymfonyApi returns two fields:
{ "token": "...", "id": "...", "refresh_token": "..." }
For authorization, you must send header for any request: Authorization: Bearer your_token.
Use
REST API on SymfonyApi developed with use api-platform bundle. You can see full documentation here.
For example:
- The Serialization Process
- The Event System
- Data Providers
- Security
- and other
Features SymfonyApi
SymfonyApi included:
- Authentication (login, register, getToken, refreshToken)
- Localization logic
- Integrated with media-server project
Authentication
For the organization of users on the application is not used FOSUserBundle. The necessary part related to the user has been ported, and all parts related to events, personal accounts, and other unnecessary information have been skipped.
If you want to use FOSUserBundle, you can delete all files associated with the user and include FOSUserBundle and configure security.yaml.
JWT is used for authentication. You can see documentation here.
Localization
Gedmo Translatable realizes localization on SymfonyApi. In order to the api-platform to return translations, the entity class must implement the Gedmo\Translatable\Translatable Interface.
The translation field will look like:
{ "translations": { "ru": { "field1": "value1", "field2": "value2" }, "en": { "field1": "value1" } } }
Similarly, to save translations, you must add the translations
parameter to the query.
It should be noted that the Gedmo Translatable does not duplicate translations.
If the application is set to English as the main language, the field translations
English will not. For example:
{ "name": "English Name", "translations": { "ru": { "name": "Russian Wonderful Name" } } }
This can be fixed by duplicate data into the App\Handler\Translation.
What's included
- api-platform/core
- doctrine/annotations
- gedmo/doctrine-extensions
- gesdinet/jwt-refresh-token-bundle
- gfreeau/get-jwt-bundle
- guzzlehttp/guzzle
- lexik/jwt-authentication-bundle
- nelmio/cors-bundle
- symfony/asset
- symfony/console
- symfony/expression-language
- symfony/flex
- symfony/framework-bundle
- symfony/lts
- symfony/maker-bundle,
- symfony/orm-pack
- symfony/swiftmailer-bundle
- symfony/twig-bundle
- symfony/validator
- symfony/yaml
Feedback
- Create a new issue
- Ask a question on сайте.
- Send a message to fafnur@yandex.ru
License MIT.