FAST API is a complete and efficient API built with modern technologies such as Cloudflare, Hono, Bun, TypeScript, Tailwind, and Redis. This project is designed to be fast, scalable, and easy to use.
- Cloudflare: Provides security and performance through its content delivery network (CDN).
- Hono: A lightweight and fast web framework for building applications in TypeScript.
- Bun: A JavaScript and TypeScript runtime that offers superior performance.
- TypeScript: A superset of JavaScript that adds static typing.
- Tailwind CSS: A utility-first CSS framework that allows for rapid and responsive design.
- Redis: An in-memory database used for caching and session management.
Follow these steps to install and set up the project on your local machine:
-
Clone the repository:
git clone https://github.com/yourusername/fast-api.git cd fast-api
-
Install Bun (if not already installed):
curl -fsSL https://bun.sh/install | bash
-
Install dependencies:
bun install
-
Configure Redis:
- Ensure Redis is installed and running. You can install it using Docker:
docker run --name redis -d -p 6379:6379 redis
- Ensure Redis is installed and running. You can install it using Docker:
-
Set up environment variables:
- Create a
.env
file in the root of the project and add the following variables:REDIS_URL=redis://localhost:6379
- Create a
Ensure the following dependencies are included in your package.json
:
{
"dependencies": {
"hono": "^3.0.0",
"redis": "^4.0.0",
"tailwindcss": "^2.0.0"
},
"devDependencies": {
"typescript": "^4.0.0",
"bun-types": "^0.1.0"
}
}
To use Cloudflare, follow these steps:
- Sign up at Cloudflare.
- Add your domain and configure the DNS records.
- Set up firewall rules and performance settings as needed.
To create routes in Hono, you can use the following example:
import { Hono } from 'hono';
const app = new Hono();
app.get('/', (c) => c.text('Hello, FAST API!'));
app.listen(3000);
To interact with Redis, you can use the following code:
import { createClient } from 'redis';
const client = createClient();
client.on('error', (err) => console.log('Redis Client Error', err));
async function connectRedis() {
await client.connect();
}
connectRedis();
To set up Tailwind CSS, follow these steps:
-
Create a Tailwind configuration file:
npx tailwindcss init
-
Configure your
tailwind.config.js
file:module.exports = { content: ['./src/**/*.{html,js,ts}'], theme: { extend: {}, }, plugins: [], };
-
Import Tailwind in your CSS file:
@tailwind base; @tailwind components; @tailwind utilities;
To run the API, use the following command:
bun run start
To deploy the API on Cloudflare, use the following command:
bun add -D @opennextjs/cloudflare
Create the wrangler.toml
file:
compatibility_date = "2024-11-08"
name = "fastapi"
[vars]
UPSTASH_REDIS_REST_TOKEN = ".................."
UPSTASH_REDIS_REST_URL = "................"
# wrangler.toml (wrangler v3.79.0^)
[observability]
enabled = true
head_sampling_rate = 1
Contributions are welcome. If you would like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/new-feature
). - Make your changes and commit (
git commit -m 'Add new feature'
). - Push to the branch.
This project is licensed under the MIT License. See the LICENSE file for details.
For more information, you can contact me at epsa@example.com.