rudolphh / koa-bp

Koa API basics, authentication with JWT, encrypting passwords with Bcrypt, and persisting data with MySQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Koa Basics, and using JWT, Bcrypt, MySQL

API Fundamentals, authentication, encryption, and persistence

Installation

Download here OR

git clone https://github.com/rudolphh/koa-bp.git
cd koa-bp
npm install

Environment

Create a .env file in the root directory of the project with the following

PORT=3030
DB_PORT=3306
DB_HOST=localhost
DB_USER=root
DB_PASS=root
DB_NAME=koa_bp_db
SECRET_KEY=somekindofsecrettext

These can be adjusted to your preference, but DB_NAME is the name of the database schema the seeder will use to automatically create some initial data for you in the database.

MySQL Installation

Make sure to have MySQL installed for your OS.

Docker MySQL

Use the link above for instructions, or if you have Docker use the docker-compose.yml file in the root folder.
In the project root, just run the command:

docker-compose up -d

Run

npm run start

Verify the deployment by navigating to your server address localhost:3030/hello in your favorite browser

Test routes

If you don't have Postman, or don't care to use it there is a test.rest file in the root directory.
This uses the Rest Client extension within VSCode for simple API testing Image of test.rest

Challenge

Build a resource (e.g. Book/Books) by adding appropriate routes, controller, and use middlewares

Example:

GET /books - retrieve ALL books
POST /book - create (insert) a new book
GET /book/id - get the book with the corresponding id
PUT /book/id - update a book with the corresponding id
DELETE /book/id - delete a book with the corresponding id

SQL update and delete statements can be found here

Note: It doesn't have to be about books, use your imagination for the kind of data you'd like to share

Used within the Project

Technology Description
node.js Evented I/O for the backend
koa Next generation web framework for Node.js
koa-body A full-featured koa body parser middleware
koa-compose Compose middleware specifically for Koa
koa-jwt Koa middleware for validating JSON Web Tokens
koa-mount Mount other Koa applications as middleware
koa-router Router middleware for koa
koa-send Static file serving middleware
koa-static Koa static file serving middleware, wrapper for koa-send
jsonwebtoken An implementation of JSON Web Tokens
bcrypt A library to help you hash passwords.
mysql2 MySQL client for Node.js with focus on performance
dotenv Loads environment variables from .env file

Development

Want to contribute? Great!

License

MIT

Free Software, Heaven Yeah!

About

Koa API basics, authentication with JWT, encrypting passwords with Bcrypt, and persisting data with MySQL


Languages

Language:JavaScript 97.4%Language:HTML 2.6%