Quick Start
Create a new Hono project for Vercel:Installation
Add Hono to your existing Vercel project:Basic Usage
Create your API in theapi directory:
api/index.ts
The
handle adapter converts your Hono app into a Vercel serverless function.Routing
Single API Route
Handle all API routes in one file usingbasePath:
api/[[...route]].ts
Multiple API Routes
Create separate files for different routes:api/users/index.ts
api/posts/index.ts
Connection Info
Get connection information:Environment Variables
Access environment variables in your Hono app:api/index.ts
- Go to your project settings
- Navigate to “Environment Variables”
- Add your variables
Configuration
Create avercel.json configuration file:
vercel.json
Middleware
CORS
api/index.ts
Authentication
api/index.ts
Deployment
1
Install Vercel CLI
2
Login to Vercel
3
Deploy
Deploy via Git
Connect your Git repository to Vercel:- Push your code to GitHub, GitLab, or Bitbucket
- Go to Vercel Dashboard
- Click “Import Project”
- Select your repository
- Configure settings and deploy
Project Structure
Typical Vercel + Hono project structure:Combining with Frontend Frameworks
With Next.js
Hono works alongside Next.js API routes:pages/api/[[...route]].ts
With React/Vite
Use Hono for the API and Vite for the frontend:package.json
Edge Functions
Deploy to Vercel’s Edge Runtime:api/edge/[[...route]].ts
Edge Functions run on Vercel’s Edge Network for ultra-low latency worldwide.
Database Integration
Vercel Postgres
api/users.ts
Vercel KV (Redis)
api/cache.ts
Best Practices
Use basePath for API routes
Use basePath for API routes
Always set
basePath('/api') to match your API directory structure.Optimize for Edge Runtime
Optimize for Edge Runtime
Use Edge Functions for globally distributed, low-latency APIs.
Use environment variables
Use environment variables
Store secrets in Vercel’s environment variables, not in code.
Implement caching
Implement caching
Use Vercel KV or edge caching for better performance.
Performance Tips
- Use Edge Functions for global distribution
- Implement caching with Vercel KV
- Optimize function memory settings
- Use ISR (Incremental Static Regeneration) when possible
- Enable compression for responses
Resources
Vercel Documentation
Official Vercel documentation
Edge Functions
Learn about Edge Functions