Skip to content

HonoJS API Example with Drizzle, Neon, and Inversify on Cloudflare Workers

License

Notifications You must be signed in to change notification settings

adrianmjim/hono-api-example

Repository files navigation

HonoJS API Example with Drizzle, Neon, and Inversify on Cloudflare Workers

This repository contains an example API built with Hono. It leverages Drizzle ORM for database operations on Neon and uses InversifyJS for dependency injection. The entire application is deployed on Cloudflare Workers for a serverless and globally distributed environment.

Deployed API Endpoint

The API is deployed and live at the following URL:

Features

  • Hono Framework: A fast, minimalist web framework designed for Cloudflare Workers.
  • Drizzle ORM: A lightweight and type-safe SQL query builder and ORM.
  • Neon Database: A serverless PostgreSQL solution.
  • InversifyJS: A robust dependency injection library to promote modular and maintainable code.
  • Serverless Deployment: Easily deploy your API on Cloudflare Workers for scalability and global performance.

Getting Started

Follow these instructions to set up the project locally and get started with development.

Prerequisites

  • Node.js
  • pnpm as your package manager
  • A Neon account with an active PostgreSQL database (Neon)

Installation

  1. Clone the repository:

    git clone https://github.com/adrianmjim/hono-api-example.git
    cd hono-api-example
  2. Install dependencies using pnpm:

    pnpm install
  3. Configure Environment Variables:

    Create a .env file in the root directory with your environment-specific variables. For example:

    DATABASE_URL=postgres://user:password@your-neon-database-url:port/database

    Adjust these variables according to your configuration.

Usage

To run the API locally, use:

pnpm dev

Deployment

To deploy the API to Cloudflare Workers:

pnpm run deploy

Make sure your wrangler.json is properly configured with your account details and project settings. This command builds and deploys your API to Cloudflare Workers.

API Endpoints

Here are some example endpoints included in this API:

  • GET /
    Returns a ok message.

  • GET /cats
    Retrieves a list of cats.

  • POST /cats
    Creates a new cat.

  • GET /cats/:id
    Retrieves a specific cat by its ID.

  • PUT /cats/:id
    Updates an existing cat.

  • DELETE /cats/:id
    Deletes an cat.

Note: These endpoints are provided as examples. Adjust or expand them to fit your application’s requirements.

🤝 Contributing contributions welcome

Contributions, issues and feature requests are welcome.

Authors

👤 Adrián Martínez Jiménez

See also the list of contributors who participated in this project.

Show Your Support

Please ⭐️ this repository if this project helped you!

📝 License

Copyright © 2025 Adrián Martínez Jiménez.

This project is licensed under the MIT License - see the LICENSE file for details.