A Boilerplate for deno RESTful apis
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.
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.
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.
Follow this Denon Installation Guide: https://deno.land/x/denon
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.
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 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:
config/roles.ts
file.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',
}
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]],
]);
This project comes with the following API routes:
Each route is secured and requires appropriate permissions to access.
We welcome contributions to this project. Please feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.