Skip to content

Emsa001/rest-api-template

Repository files navigation

Express.js RestAPI

This project is a REST API template built with Express.js. It serves as a starting point for building RESTful APIs using Node.js and Express.

Logo

Installation

Clone the repository:

git clone https://github.com/Emsa001/rest-api-template.git
cd rest-api-template

Install dependencies:

  npm install

Usage

Copy and change the values of .env and .keys.json as needed:

cp .env.example .env
cp .keys.example.json .keys.json

Start the development server:

npm start

Databases

Sequelize allows you to manage multiple databases effortlessly. You can add as many databases as you need, but ensure that you keep the models for each database separate.

// Initialize the first database
const db1 = new Database("db1", { dialect: "sqlite", storage: "./database1.sqlite", logging: false });
// Initialize database with models in directory ./models1
await db1.init("./models1");

// Initialize the second database
const db2 = new Database("db2",{
    dialect: "mysql",
    host: process.env.DB_HOST,
    database: process.env.DB_DATABASE,
    username: process.env.DB_USERNAME,
    password: process.env.DB_PASSWORD,
});
// Initialize database with models in directory ./models2
await db2.init("./models2");

Examples

Hello with params

  GET /public/hello/:user
Parameter Type Description
user string Required Username

Hello2 with query values

  GET /public/hello2?user=...
Parameter Type Description
user string Required Username

Authorized Request

  GET /auth/hello
HEADER Type value
authorization Bearer Token superSecretKey1

Features

  • Structured REST API template
  • Multiple Database Support
  • Bearer authorization with permissions
  • Error Handling with saving to logs
  • Requestss logging

Authors

License

MIT

About

Rest API built with express.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published