create an .env file and insert following to it:
PORT=[replace this with your specific port]
you should create a mySql database with name "book_directory" .
CREATE DATABASE IF NOT EXISTS book_directory
after creating a database, inside database create a table with name "book", with SQL query:
CREATE TABLE IF NOT EXISTS Book(
id int AUTO_INCREMENT PRIMARY KEY,
title varchar(250) unique not null,
author varchar(250) not null,
edition int
)
inside .env file insert the following:
DB_HOST=
DB_USERNAME=
PASSWORD=
DB_NAME=
CREATE TABLE IF NOT EXISTS `User`(
id int AUTO_INCREMENT PRIMARY KEY,
firstName varchar(100) NOT NULL,
lastName varchar(100) NOT NULL,
email varchar(250) UNIQUE NOT NULL,
password varchar(250) NOT NULL,
createdAt timestamp DEFAULT CURRENT_TIMESTAMP
)
POST http://localhost:9000/auth/signup
- send user data inside post body request as a JSON raw
- user data are : { "firstName", "lastName", "email", "password" }
- there are validation rules.
- you must login to get a token, that gives you authorization to book routes.
- route: POST http://localhost:9000/auth/login
- send login data in post body request as a JSON raw.
- login data are { "email", "password" }
- there are validation rules.
- successful login request will return a token, this token is used in the Authorization header with type of "Bearer Token" with Book routes.
- Don't Forget to set the token that you got from login request
- route: GET http://localhost:9000/book
- token required.
- route: GET http://localhost:9000/book/[bookId]
- replace [book id] with your book id, ex: GET http://localhost:9000/book/1
- there is a validation rules on bookId
- token required.
- route: POST http://localhost:9000/book
- send book data in post body request as a type of JSON raw.
- book data are { "title", "author", "edition" }.
- there is a validation rules on book data.
- token required.
- route: PUT http://localhost:9000/book/[bookId]
- replace [book id] with your book id, ex: PUT http://localhost:9000/book/1
- send new book data in PUT body request as a type of JSON raw.
- new book data are { "title", "author", "edition" }.
- there is a validation rules on book data.
- token required.
- route: Delete http://localhost:9000/book/[bookId]
- replace [book id] with your book id, ex: DELETE http://localhost:9000/book/1
- there is a validation rules on bookId.
- token required.