Hey, Dev.to community! Today, I'm excited to introduce you to Deno REST, a straightforward boilerplate project for building RESTful APIs using Deno, Oak, and deno_mongo. Deno is a secure runtime for JavaScript and TypeScript, Oak is a middleware framework for Deno's HTTP server, and deno_mongo is a MongoDB driver for Deno.
Features
Deno REST comes packed with several useful features to help you jumpstart your API development:
- Organized by Model, Controller, Service structure
- MongoDB integration with deno_mongo
- JWT-based authentication
- User authorization with role-based access control
- CORS support for handling cross-origin requests
- Environment management via .env files
- Request validation to ensure valid data
- Graceful error handling
- Database seeding for initial data
- User roles and permissions management
- Password hashing with BCrypt
- Denon integration for automatic server restarts
- Integration tests for easy testing
- Docker and CircleCI integration for containerization and continuous integration
Libraries Utilized
Deno REST leverages the following libraries:
- Oak - Middleware framework for Deno's net server
- deno_mongo - MongoDB driver for Deno
- cors - CORS middleware for Deno
- djwt - JSON Web Tokens in Deno, based on JWT and JWS specifications
- yup - Schema builder for value parsing and validation
- bcrypt - OpenBSD Blowfish password hashing algorithm
Getting Started
To get started with Deno REST, follow these steps:
- Install Deno: Instructions and official installation guide
-
Set up Environment Variables: Review the
.environments/.env.example
file and create a suitable.env
file based on your needs. - Install Denon: Follow the Denon installation guide
-
Database Seeding: Use the provided seeding script to populate the database with initial data:
denon run --allow-read --allow-write --allow-net --unstable seed.ts
-
Running the Project: Start the project using the following command:
denon start
User Roles and Permissions
Customize user roles and permissions by modifying the config/roles.ts
file.
API Routes
Deno REST includes the following API routes:
- GET /users
- GET /users/:id
- POST /users
- PUT /users/:id
- DELETE /users/:id
Contributing and License:
Contributions to Deno REST are welcome! You can open issues or submit pull requests. The project is licensed under the MIT License.
Conclusion:
With Deno REST, you can kickstart your RESTful API development using Deno, Oak, and deno_mongo. It provides a clean architecture, essential features, and integration with popular libraries, allowing you to focus on building your API logic.
Give Deno REST a try and let us know your feedback! You can find the complete project and documentation on GitHub.
Thank you for reading, and happy coding with Deno REST!
Top comments (0)