This is a simple API built with nodejs, expressjs, and mysql.
I built this for freeCodeCamp's Random Quote Machine project.
-
Installation:
- Clone this repo
- run
npm install
to install all dependencies - Install MYSQL and start the server:
- Open the .env-example file and update the necessary database configs (database username, database password, database host, etc)
- Run
npx sequelize db:migrate
to run the migrations and create all the database tables (make sure MSQL is running) - Run
npx sequelize db:seed:all
to seed the database with fake data generated with Faker - run
npm start
to run the app
- Clone this repo
-
Get Requests
- Get All Quotes
localhost:3000/api/quotes
will return all quotes, paginated at 10 records per page.- to navigate between paginated page results, do
localhost:3000/api/quotes?page=2
and so on
- to navigate between paginated page results, do
- Get A single Quote
localhost:3000/api/quotes/1
will return the quote with an id of 1
- Get Quotes by Author ID
localhost:3000/api/quotes?authorId=3
will return all quotes for the author with an id of 3
- Get All Authors
localhost:3000/api/authors
will return all authors paginated at 10 records per page.- to navigate between paginated page results, do
localhost:3000/api/authors?page=2
and so on
- to navigate between paginated page results, do
- Get a Single Author by ID
localhost:3000/api/authors/1
will return the author with an id of 1
- Get Author By Name
localhost:3000/api/authors?authorName=<author's name here>
- Get All Quotes
-
Post Requests