Skip to content

m4v1/celebapi-express

Repository files navigation

Celebapi Express

dependencies Status Build Status License: MIT Codacy Badge Codacy Badge

Celebapi Express is a nodejs rest api to retrieve informations about celebrities and store them in a mysql database. It can use a redis chache, enabled in the .env configuration file.

Prerequisites

You need to have Node and MySQL installed to run this app.

At the moment you can only use MySQL as persistence.

If you want to use to cache system, you need to have Redis installed.

In production environmnet you can use:

Sentry.io to log exceptions. Configure related variables in your .env file.

Datadog as an apm for your API. Set USE_DATADOG to true in your .env config file to enable tracing.

Installation

Use the package manager npm to install Celebapi Express.

git clone https://github.com/m4v1/celebapi-express
cd celebapi-express
npm i
mv .env.orig .env

now edit .env file and add your configuration, then:

npm run build

will build the code and put it into the /dist folder.

You should also edit Knex configuration file knexfile.js according to your MySQL config.

Use Knex command line tool to run db migrations:

npx cross-env NODE_ENV=production knex migrate:latest

Now to start the api with:

npm run prod

If you use PM2 to run node apps (and you should), you can start the api with the ecosystem file provided in the repository, and of course you can edit it with your preferences:

pm2 start ecosystem.config.js

Usage

to get infos you use the /info/ route and the urlencoded name as parameter:

curl -X GET host:port/info/michael%20jackson

and you will get:

{
  "data": {
    "name": "michael jackson",
    "bday": "1958-08-29",
    "bplace": "Gary IN",
    "bio": "The King of Pop who became the most successful singer in American history etc."
  },
  "message": "remote",
  "status": 200
}

to get videos you use the /videos/ route and the urlencoded name as parameter:

curl -X GET host:port/videos/michael%20jackson

and you will get 6 youtube videos:

{
  "data": [
    {
      "link": "https://www.youtube.com/watch?v=h_D3VFfhvs4",
      "title": "Michael Jackson - Smooth Criminal (Official Video)",
      "thumb": "https://i.ytimg.com/vi/h_D3VFfhvs4/hqdefault.jpg"
    },
    {
      "link": "https://www.youtube.com/watch?v=Zi_XLOBDo_Y",
      "title": "Michael Jackson - Billie Jean (Official Music Video)",
      "thumb": "https://i.ytimg.com/vi/Zi_XLOBDo_Y/hqdefault.jpg"
    },
    {
      "link": "https://www.youtube.com/watch?v=sOnqjkJTMaA",
      "title": "Michael Jackson - Thriller (Official Video)",
      "thumb": "https://i.ytimg.com/vi/sOnqjkJTMaA/hqdefault.jpg"
    },
    {
      "link": "https://www.youtube.com/watch?v=LeiFF0gvqcc",
      "title": "Michael Jackson - Remember The Time (Official Video)",
      "thumb": "https://i.ytimg.com/vi/LeiFF0gvqcc/hqdefault.jpg"
    },
    {
      "link": "https://www.youtube.com/watch?v=oRdxUFDoQe0",
      "title": "Michael Jackson - Beat It (Official Video)",
      "thumb": "https://i.ytimg.com/vi/oRdxUFDoQe0/hqdefault.jpg"
    },
    {
      "link": "https://www.youtube.com/watch?v=-i9zrCR9NDU",
      "title": "Michael Jackson's Ghost Speaks To Me At The Neverland Ranch",
      "thumb": "https://i.ytimg.com/vi/-i9zrCR9NDU/hqdefault.jpg"
    }
  ],
  "message": "remote",
  "status": 200
}

Contributing

Pull requests are welcome.

For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

About

API in Express.js to retrieve celebrities data.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors