Forem

Cover image for Building RESTful APIs with Deno: A Boilerplate for Rapid Development
Vicky Gonsalves
Vicky Gonsalves

Posted on

Building RESTful APIs with Deno: A Boilerplate for Rapid Development

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:

  1. Install Deno: Instructions and official installation guide
  2. Set up Environment Variables: Review the .environments/.env.example file and create a suitable .env file based on your needs.
  3. Install Denon: Follow the Denon installation guide
  4. 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
    
  5. 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!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more