Home

Awesome

Deno REST - A Deno RESTful API Boilerplate

Deno Logo

CircleCI

Deno REST is a straightforward boilerplate project for creating RESTful APIs using Deno, Oak, and deno_mongo. Deno is a secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust, Oak is a middleware framework for Deno's http server, and deno_mongo is a MongoDB driver for Deno.

Features

Libraries Utilized

Getting Started

Installation / Upgrade

To get started with this project, you first need to have Deno installed. If you haven't installed it already, you can follow the official Installation Guide.

Environment Variables

Review the .environments/.env.example file and create a suitable .env file based on your needs. For example, create a .env.development file under the .environments directory for a development environment. For a test environment, create a .env.test file under the .environments directory. Then, add the necessary variables.

Install Denon

Follow this Denon Installation Guide: https://deno.land/x/denon

Database Seeding

We use a seeding script to populate the database with initial data. Run the following command to execute the seeding script:

denon run --allow-read --allow-write --allow-net --unstable seed.ts

Ensure that you have the necessary permissions by including the --allow-read and --allow-write flags.

Running the Project

After setting up everything, you can run the project using the following command:

denon start

The server will start and listen for incoming requests.

User Roles and Permissions

User roles and permissions are defined in the config/roles.ts file. You can add, modify, or remove roles and their associated permissions in this file.

To add a new role, follow these steps:

  1. Open the config/roles.ts file.
  2. Add a new role to the enum Role declaration. For example, to add a GUEST role, your enum Role might look like this:
export enum Role {
  USER = 'USER',
  ADMIN = 'ADMIN',
  GUEST = 'GUEST',
}
  1. Define permissions for the new role in the roleRights object. For example, to allow a GUEST to view users but not modify them, your roleRights object might look like this:
export const roleRights = new Map([
  [Role.USER, [
    PermissionList.GET_USER,
    PermissionList.POST_USER,
    PermissionList.PUT_USER,
    PermissionList.DELETE_USER,
  ]],
  [Role.ADMIN, [
    PermissionList.GET_USER,
    PermissionList.POST_USER,
    PermissionList.PUT_USER,
    PermissionList.DELETE_USER,
    PermissionList.MANAGE_ROLES,
  ]],
  [Role.GUEST, [PermissionList.GET_USER]],
]);

API Routes

This project comes with the following API routes:

Each route is secured and requires appropriate permissions to access.

Contributing

We welcome contributions to this project. Please feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License.