Simple single file REST-API using:
- ExpressJS For basic routing handler
- Sequelize for Databases (MySQL) ORM
- body-parser for HTTP POST method handler
- multer for multipart-form and file upload handling
- MySQL database
Make sure you have installed NodeJS and MySQL server on your local machine.
- Clone this repo to your local machine
- Create new database using MySQL database. Grab bookstore.sql included in this repo and import into your MySQL server.
cd
to your local repo directory and runnpm install
using Terminal or Windows PowerShell- Please look into lines bellow and configure your database and port:
//Set app config
const port = 3000;
const baseUrl = 'http://localhost:'+port;
//Connect to database
const sequelize = new Sequelize('bookstore', 'root', 'yourpassword', {
host: 'localhost',
dialect: 'mysql',
pool: {
max: 5,
min: 0,
idle: 10000
}
});
- Run
node index.js
to start the server
GET /book/
Get all books
GET /book/<isbn>
Get book by ISBN
POST /book/add
Add new book into collection
POST /book/:isbn/update
Update existing book
POST /book/<isbn>
Delete book by ISBN