This project showcases a performant API built with Deno 2.0 and Hono.js. It includes message handling, caching, validation, and security features.
- Deno 2.0: A modern, fast JavaScript/TypeScript runtime.
- Hono.js: Ultra-fast web framework for handling requests.
- Message Caching: Uses a cache to store messages with timestamps.
- Validation: Validates request body using
Zod
. - Security: Secure headers for enhanced API security.
- CORS & Logging: CORS and request logging are enabled for better API handling.
-
Install Deno (if not already installed):
deno --version
-
Clone the repository:
git clone https://github.com/sherbolotarbaev/deno-hono.git cd deno-hono
-
Run the API:
deno task dev
The server will start on
http://localhost:999
.
-
GET /messages: Fetch all cached messages.
Example:
curl http://localhost:999/messages
-
POST /messages: Add a new message to the cache. Expects a JSON body:
{ "message": "Your message here" }
Example:
curl -X POST http://localhost:999/messages \ -H "Content-Type: application/json" \ -d '{"message": "Hello World"}'
Messages are cached daily, using a date-based key format. Cached messages can be fetched via GET /messages
or added via POST /messages
.
The API is secured with:
- CORS: Allows cross-origin requests.
- Secure Headers: Provides protection against common web vulnerabilities.
-
To lint or format your code, use Deno's built-in tools:
deno lint deno fmt
Contributions are welcome! Please submit issues or pull requests.