Skip to content

arissetyawan/express-rest-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-rest-api

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

Install

Make sure you have installed NodeJS and MySQL server on your local machine.

  1. Clone this repo to your local machine
  2. Create new database using MySQL database. Grab bookstore.sql included in this repo and import into your MySQL server.
  3. cd to your local repo directory and run npm install using Terminal or Windows PowerShell
  4. 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
    }
});
  1. Run node index.js to start the server

Routes

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


Test

You can get Postman collections of this REST-API here

About

Simple REST-API with ExpressJS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%