EdgeMaster Examples
Learn by example! We provide 10 comprehensive examples covering common use cases.
🚀 Quick Start Examples
1. API Gateway
Complete REST API with CRUD operations, pagination, and validation.
Features:
- HTTP method helpers
- Request/response parsing
- Input validation
- Error handling
- CORS support
2. JWT Authentication
Full authentication system with JWT tokens, protected routes, and RBAC.
Features:
- User registration & login
- Token generation with
jose - Protected routes
- Role-based access control
- Token refresh
📚 All Examples
| Example | Description | Status |
|---|---|---|
| 01-api-gateway | Complete REST API | ✅ Full code |
| 02-authentication | JWT auth system | ✅ Full code |
| 03-caching | Cache strategies | 📖 Documented |
| 04-microservices-proxy | Service routing | 📖 Documented |
| 05-security | Rate limiting & security | 📖 Documented |
| 06-ab-testing | A/B testing & feature flags | 📖 Documented |
| 07-image-optimization | Image transformation | 📖 Documented |
| 08-workers-kv | KV storage integration | 📖 Documented |
| 09-workers-ai | AI integration (2025) | 📖 Documented |
| 10-rpc-bindings | RPC service bindings (2025) | 📖 Documented |
🎯 Learning Paths
For Beginners
- Start with API Gateway
- Add Authentication
- Implement Security
For API Developers
- API Gateway - REST patterns
- Authentication - Secure APIs
- Caching - Performance
- Security - Rate limiting
For Microservices
- Microservices Proxy - Service routing
- RPC Bindings - Inter-service communication
For Advanced Features
- Workers KV - Persistent storage
- Workers AI - AI integration
- A/B Testing - Feature flags
💡 Quick Snippets
Simple Hello World
import { EdgeController, RouteHandler, Task, json } from 'edge-master';
const app = new EdgeController();
app.GET('/hello', new RouteHandler(new Task({
do: async () => json({ message: 'Hello World!' })
})));
export default {
fetch: (req: Request) => app.handleRequest({ req })
};
With CORS and Logging
import { corsInterceptor, loggingInterceptor } from 'edge-master';
app.addInterceptor(corsInterceptor({ origin: '*' }));
const { request, response } = loggingInterceptor();
app.addInterceptor(request);
app.addInterceptor(response);
Protected Route
import { jwtInterceptor, getState } from 'edge-master';
app.addInterceptor(jwtInterceptor({
verify: (token) => verifyJWT(token, secret),
exclude: ['/public/*']
}));
app.GET('/profile', new RouteHandler(new Task({
do: async (ctx) => {
const user = getState(ctx, 'user');
return json({ user });
}
})));
🔗 External Resources
📝 Contributing Examples
Have a great example? We'd love to include it!
- Fork the repository
- Create your example in
example/XX-example-name/ - Include README, code, and configuration
- Submit a pull request
Need help? Open an issue or email us