Version 1.0.0
This project is a REST API for Bilemo to allow partners to display their mobile phones catalog. This API was built with Symfony 3.4. It's the 7th OpenClassRooms PHP/Symfony Developer project. A working documentation demo can be found here.
As you can see there are two folders:
- diagrams folder where you will find project related usefull diagrams.
- api folder where you will find REST API source code.
Below the instructions to use Bilemo REST API from your application.
- PHP >=7.0.10
- MySQL
- PHPUnit 6.5
- Composer to install Symfony 3.4 and project dependencies
This project uses:
- FOSRestBundle to simplify REST API creation
- FOSOAuthServerBundle to manage Bilemo partners OAuthentication
- JMSSerializerBundle to easily serialize, and deserialize data (needed by BazingaHateoasBundle)
- NelmioApiDocBundle to generate API documentation
- BazingaHateoasBundle to implement representations for HATEOAS REST
Those dependencies are included in composer.json.
- Clone this repository on your local machine by using this command line in your folder
git clone https://github.com/bhalexx/bilemo.git
. - In project folder open a new terminal window and execute command line
composer install
. - Rename
bilemo/app/config/parameters.yml.dist
inbilemo/app/config/parameters.dist
and edit database parameters with yours. - Edit
root
,root_uri
andpicture_path
parameters inconfig_dev.yml
with your project path. - Execute command line
php bin/console bilemo:fixtures:load
. This command will create database and load some fixtures. - Your project is now up to date!
This API is restricted to Bilemo partners. When a Bilemo admin adds your application as a new partner, your credentials are sent by email.
For demo you can also run this command to create your application as a Bilemo partner:
php bin/console bilemo:partner:create {YourApplicationName} {YourPassword} {YourEmail} {YourRedirectURI}
This command will output:
username: {YourApplicationName}
password: {YourPassword}
client_id: {YourClientId}
client_secret: {YourClientSecret}
Now that you're a Bilemo partner, you need to get an access token to access API methods.
Set Content-Type: application/json
in your request headers and do a POST request on /oauth/v2/token
with those JSON parameters in request body:
{
"grant_type": "password",
"client_id": "{YourClientId}",
"client_secret": "{YourClientSecret}",
"username": "{YourApplicationName}",
"password": "{YourPassword}"
}
You will get an access_token
and a refresh_token
and you can now access API endpoints by setting those parameters in each request headers:
Content-Type: application/json
Authorization: Bearer {YourAccessToken}
Your access token expires after 1 hour. To get a new access token use your refresh token in your POST request headers on /oauth/v2/token
with those parameters:
{
"grant_type": "refresh_token",
"client_id": "{YourClientId}",
"client_secret": "{YourClientSecret}",
"refresh_token": "{YourRefreshToken}"
}
Now you'ready to enjoy! Refer to documentation to use API endpoints according to your needs.
Still for demo you can also create your application as a Bilemo administrator by running the same command with the optional parameter admin
:
php bin/console bilemo:partner:create {YourApplicationName} {YourPassword} {YourEmail} {YourRedirectURI} admin
This API project is as documented as possible, so you can find:
- a full documentation of API methods by adding
/api/doc
at the end of your API URI. - and some diagrams
Two other projects were created to show how to use this API:
- Bilemo Admin - the Bilemo administration application
- OpenMobileRooms - a Bilemo B2B partner application