ftm-pm/symfony-api

This package is abandoned and no longer maintained. No replacement package was suggested.

The SymfonyApi is configured bundles for creating a REST API.

0.1.0 2018-03-25 06:06 UTC

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

License MIT.