2017 © Pedro Peláez
 

project symfony-api

The SymfonyApi is configured bundles for creating a REST API.

image

ftm-pm/symfony-api

The SymfonyApi is configured bundles for creating a REST API.

  • Saturday, July 28, 2018
  • by Fafnur
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

SymfonyApi

The SymfonyApi is configured bundles for creating a REST API., (*1)

Russian documentation here., (*2)

Setup

The SymfonyApi is a symfony/skeleton application with bundles:, (*3)

Installation

Run the Composer command to create a new project, (*4)

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., (*5)

Next step, run command to update database., (*6)

php bin/console d:s:u --force

In SymfonyApi, authorization was developed using JWT. You can see documentation here., (*7)

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:, (*8)

{
  "username": "johndoe",
  "password": "test",
  "email": "johndoe@example.com"
}

or using curl, (*9)

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:, (*10)

{
  "username": "johndoe",
  "password": "test"
}

or using curl, (*11)

curl -X POST http://my-project/api/token -d username=johndoe -d password=test

The SymfonyApi returns two fields:, (*12)

{
  "token": "...",
  "id": "...",
  "refresh_token": "..."
}

For authorization, you must send header for any request: Authorization: Bearer your_token., (*13)

Use

REST API on SymfonyApi developed with use api-platform bundle. You can see full documentation here., (*14)

For example: * The Serialization Process * The Event System * Data Providers * Security * and other, (*15)

Features SymfonyApi

SymfonyApi included: * Authentication (login, register, getToken, refreshToken) * Localization logic * Integrated with media-server project, (*16)

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., (*17)

If you want to use FOSUserBundle, you can delete all files associated with the user and include FOSUserBundle and configure security.yaml., (*18)

JWT is used for authentication. You can see documentation here., (*19)

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., (*20)

The translation field will look like:, (*21)

{
  "translations": {
     "ru": {
        "field1": "value1",
        "field2": "value2"
     },
     "en": {
         "field1": "value1"
     }
  }
}

Similarly, to save translations, you must add the translations parameter to the query., (*22)

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:, (*23)

{
  "name": "English Name",
  "translations": {
     "ru": {
        "name": "Russian Wonderful Name"
     }
  }
}

This can be fixed by duplicate data into the App\Handler\Translation., (*24)

, (*25)

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, (*26)

Feedback

  • Create a new issue
  • Ask a question on сайте.
  • Send a message to fafnur@yandex.ru

License MIT., (*27)

The Versions