This project is a boilerplate codebase for building a high-performance, globally distributed REST API using Cloudflare Workers, HonoJS, Redis, and NextJS. This project includes a speed search feature for country names, rate limiting, and caching mechanisms.
- Cloudflare Workers - Serverless Edge: Employed for its exceptional speed, low overhead, and global distribution.
- HonoJS - Web Framework: Used for its lightweight and efficient design, perfect for serverless environments.
- Redis - In-Memory Data Store: Serves as the primary data storage for fast and efficient data retrieval.
- NextJS - Frontend Framework: Utilised for building the frontend application.
Before getting started with the project, ensure you have the following tools installed or ready:
- Postman: Used for making API requests and testing the functionality of the endpoints.
- Upstash Redis: Serveless Cloud Redis database for this application.
- Vercel: Used for deploying the NextJS frontend application.
- Cloudflare Workers: Used for deploying the HonoJS REST API and managing the domain.
The project boasts the following features:
- Speed Search: Efficiently search for country names using Redis zstack data structure.
- Rate Limiting: Implement a 20s rate limiting mechanism to avoid server overloading.
- Caching: Utilise caching to improve performance and reduce server load.
To get started with the project, follow the instructions below:
-
Clone the repository:
https://github.com/remediios/hono-redis-rest-api.git
-
Navigate to the project directory:
cd hono-redis-rest-api
-
Install the dependencies:
pnpm install
-
Set up your Upstash Redis database and Cloudflare Workers KV namespace.
-
Create a
.env
file with the following credentials:
# .env Example
# UPSTASH REDIS CREDENTIALS
UPSTASH_REDIS_REST_TOKEN="..."
UPSTASH_REDIS_REST_URL="..."
- Create a
wrangler.toml
file with the following credentials:
# wrangler.toml Example
#Your project name for Cloudflare
name = "hono-redis-rest-api"
#Your project date
compatibility_date = "2024-04-02"
# UPSTASH REDIS CREDENTIALS
[vars]
UPSTASH_REDIS_REST_TOKEN = "..."
UPSTASH_REDIS_REST_URL = "..."
The wrangler.toml
configuration file is used to customize the development and deployment setup for a Cloudflare Worker.
- Run the application with
pnpm run dev
After completing these steps, you should be able to run this project locally or adapt it to production (Cloudflare and Vercel). If you encounter any issues or have any questions, please don't hesitate to reach out.
After running the application, you can access it at http://localhost:3000
. Both client and API are accessible within the same PORT. This is achieved by using NextJS API mechanism where the HonoJS API is implemented.
Contributions to the project are more than welcome. Please submit a pull request with a detailed description of your changes.
Fastify-Prisma-Rest-API is open-source software licensed under the MIT License.
For any questions or feedback, please reach out to miguelremediioss@gmail.com
.