Skip to main content

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

View Example →

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

View Example →


📚 All Examples

ExampleDescriptionStatus
01-api-gatewayComplete REST API✅ Full code
02-authenticationJWT auth system✅ Full code
03-cachingCache strategies📖 Documented
04-microservices-proxyService routing📖 Documented
05-securityRate limiting & security📖 Documented
06-ab-testingA/B testing & feature flags📖 Documented
07-image-optimizationImage transformation📖 Documented
08-workers-kvKV storage integration📖 Documented
09-workers-aiAI integration (2025)📖 Documented
10-rpc-bindingsRPC service bindings (2025)📖 Documented

🎯 Learning Paths

For Beginners

  1. Start with API Gateway
  2. Add Authentication
  3. Implement Security

For API Developers

  1. API Gateway - REST patterns
  2. Authentication - Secure APIs
  3. Caching - Performance
  4. Security - Rate limiting

For Microservices

  1. Microservices Proxy - Service routing
  2. RPC Bindings - Inter-service communication

For Advanced Features

  1. Workers KV - Persistent storage
  2. Workers AI - AI integration
  3. 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!

  1. Fork the repository
  2. Create your example in example/XX-example-name/
  3. Include README, code, and configuration
  4. Submit a pull request

Contribution Guide


Need help? Open an issue or email us