Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marc-kruiss/hono-clouflare-worker-todo-api
This Hono application is a serverless REST API designed for Cloudflare Workers, utilizing Deno's Hono framework. It efficiently manages to-do items, leveraging Cloudflare's KV database for storage and the Wrangler CLI for seamless deployment. This setup offers a scalable, low-latency solution for task management in a distributed environment.
https://github.com/marc-kruiss/hono-clouflare-worker-todo-api
cloudflare cloudflare-api cloudflare-kv cloudflare-worker cloudflare-workers hono honojs jwt jwt-authentication middleware rest-api serverless-architectures wrangler-cli
Last synced: 25 days ago
JSON representation
This Hono application is a serverless REST API designed for Cloudflare Workers, utilizing Deno's Hono framework. It efficiently manages to-do items, leveraging Cloudflare's KV database for storage and the Wrangler CLI for seamless deployment. This setup offers a scalable, low-latency solution for task management in a distributed environment.
- Host: GitHub
- URL: https://github.com/marc-kruiss/hono-clouflare-worker-todo-api
- Owner: Marc-Kruiss
- Created: 2023-12-28T19:19:53.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2023-12-30T20:20:59.000Z (11 months ago)
- Last Synced: 2024-10-04T22:11:12.273Z (about 2 months ago)
- Topics: cloudflare, cloudflare-api, cloudflare-kv, cloudflare-worker, cloudflare-workers, hono, honojs, jwt, jwt-authentication, middleware, rest-api, serverless-architectures, wrangler-cli
- Language: TypeScript
- Homepage:
- Size: 14.6 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Hono Framework API
This is a RESTful API built using the Hono framework, which leverages Cloudflare environment variables, JWT authentication, and the Cloudflare KV database.
## Table of Contents
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Usage](#usage)
- [Middleware](#middleware)
- [Endpoints](#endpoints)
- [Error Handling](#error-handling)
- [Contributing](#contributing)
- [License](#license)## Prerequisites
Before using this API, make sure you have the following prerequisites in place:
- Node.js installed on your system.
- Access to a Cloudflare Workers environment.
- Cloudflare KV database set up with a namespace named "TODOS."
- JWT secret key for authentication.## Installation
1. Clone this repository to your local machine.
2. Install the necessary dependencies by running the following command: `npm start`This will launch the API, and it will be accessible at the specified route.
## Middleware
The API uses various middleware functions for handling requests and authentication. These include:
- `helloMiddleware`: Logs a greeting message.
- `superSecretWeapon`: Sets a secret value in the request context.
- `authenticateUser`: Authenticates users based on a Bearer token.
- `authMiddleware`: JWT token verification middleware.You can customize these middleware functions according to your requirements.
## Endpoints
### Swagger UI
- Access the Swagger UI documentation at `/docs`.
### Get Requests
- `/`: Root endpoint with sample middleware and authentication.
- `/error`: Throws a sample error.
- `/ghl`: Logs the request body.
- `/todos`: Retrieves todos for a specific user.
- `/api/todos`: Retrieves all todos.### Post Request
- `/api/todos`: Adds a new todo item for a specific user.
## Error Handling
The API includes error handling for various scenarios. Custom errors are defined in the `error.ts` file. The API returns appropriate HTTP status codes and error messages.
## Contributing
Contributions to this project are welcome. Please follow the standard GitHub Fork and Pull Request workflow.
## License
This project is licensed under the [MIT License](LICENSE).