Emotional API is a web REST-Ful API based on Laravel framework, which serve as services and data provider for Emotional Frontend.
Emotional API using Spotify and Youtube APIs to provide songs data. You must have APIs keys and secrets in order to have fully functional APIs.
You need to install the required libraries and configure the Environment Variables in .env file with your APIs keys and secrets.
Please check the official laravel installation guide for server requirements before you start. Official Documentation
Alternative installation is possible without local dependencies relying on Docker.
Clone the repository
git clone git@github.com:limitless-brain/emotional-backend.git
Switch to the repo folder
cd emotional-backend
Install all the dependencies using composer
composer install
Copy the example env file and make the required configuration changes in the .env file
cp .env.example .env
Generate a new application key
php artisan key:generate
Configure passport
php artisan passport:install
Run the database migrations (Set the database connection in .env before migrating)
php artisan migrate
Start the local development server
php artisan serve
You can now access the server at http://localhost:8000
TL;DR command list
git clone git@github.com:limitless-brain/emotional-backend.git
cd emotional-backend
composer install
cp .env.example .env
php artisan key:generate
php artisan passport:install
Make sure you set the correct database connection information before running the migrations Environment variables
php artisan migrate
php artisan serve
Due to github file size restrictions, big files has been moved to google drive. Shared Files
- Emotional AI files should be extracted to /app/Python .
- Emotional db files should be extracted to /database .
Populate the database with seed data with relationships which includes users, articles, comments, tags, favorites and follows. This can help you to quickly start testing the api or couple a frontend and start using it with ready content.
Open the DummyDataSeeder and set the property values as per your requirement
database/seeders/DatabaseSeeder.php
Run the database seeder, and you're done
php artisan db:seed
Note : It's recommended to have a clean database before seeding. You can refresh your migrations at any point to clean the database by running the following command
php artisan migrate:refresh
-
Python3 to call the AI model and make the prediction.
sudo apt install python3 python3-pip
- In order to install the required libraries for the AI and test at the same time,
run the script model script.
python3 app/Python/emotional_ai.py
- In order to install the required libraries for the AI and test at the same time,
run the script model script.
-
YT-DL to download videos from youtube.
sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl sudo chmod a+rx /usr/local/bin/youtube-dl sudo apt install ffmpeg
To install with Docker, run following commands:
git clone git@github.com:gothinkster/laravel-realworld-example-app.git
cd laravel-realworld-example-app
cp .env.example.docker .env
docker run -v $(pwd):/app composer install
cd ./docker
docker-compose up -d
docker-compose exec php php artisan key:generate
docker-compose exec php php artisan jwt:generate
docker-compose exec php php artisan migrate
docker-compose exec php php artisan db:seed
docker-compose exec php php artisan serve --host=0.0.0.0
The api can be accessed at http://localhost:8000/api.
This contains all APIs specification which make the development of frontend much easier.
- passport - For authentication using JSON Web Tokens
- laravel-cors - For handling Cross-Origin Resource Sharing (CORS)
app/Models
- Contains all the Eloquent modelsapp/Http/Controllers/Api
- Contains all the api controllersapp/Http/Middleware
- Contains the Passport auth middlewareconfig
- Contains all the application configuration filesdatabase/factories
- Contains the model factory for all the modelsdatabase/migrations
- Contains all the database migrationsdatabase/seeds
- Contains the database seederroutes
- Contains all the api routes defined in api.php filetests
- Contains all the application tests
.env
- Environment variables can be set in this file-
- DB_CONNECTION=mysql
- DB_HOST=127.0.0.1
- DB_PORT=3306
- DB_DATABASE=emotional
- DB_USERNAME=fswt
- DB_PASSWORD=FSwt.1994
-
- SPOTIFY_CLIENT_ID="YOUR CLIENT ID"
- SPOTIFY_CLIENT_SECRET="YOUR CLIENT SECRET"
-
- YOUTUBE_API_SECRET_KEY="YOUR SECRET"
-
Run the laravel development server
php artisan serve
The api can now be accessed at
http://localhost:8000/api/v1
Request headers
Required | Key | Value |
---|---|---|
Yes | Content-Type | application/json |
Yes | X-Requested-With | XMLHttpRequest |
Optional | Authorization | Token {Bearer} |
Refer the api specification for more info.
This application uses Passport Tokens to handle authentication. The token is passed with each request using the Authorization
header with Token
scheme. The Passport authentication middleware handles the validation and authentication of the token. Please check the following source to learn more about Passport.
This applications has CORS enabled by default on all API endpoints. The default configuration allows requests from http://localhost:3000
to help speed up your frontend testing. The CORS allowed origins can be changed by setting them in the config file. Please check the following sources to learn more about CORS.