Endpoint Generator
The endpoint generator creates HTTP request handlers for your Azu application. Endpoints are the controllers that handle incoming HTTP requests and return responses.
Overview
azu generate endpoint <name> [options]Basic Usage
Generate a Simple Endpoint
# Generate a basic endpoint
azu generate endpoint users
# Generate with namespace
azu generate endpoint admin/users
# Generate API endpoint
azu generate endpoint api/v1/users --apiGenerate CRUD Endpoints
# Generate full CRUD operations
azu generate endpoint posts --actions index,show,create,update,destroy
# Generate specific actions only
azu generate endpoint comments --actions index,createCommand Options
--api
Generate API-only endpoints (no pages/templates)
false
--actions <list>
Specify which actions to generate
all CRUD actions
--skip-tests
Don't generate test files
false
--skip-routes
Don't register routes automatically
false
--force
Overwrite existing files
false
Generated Files
Basic Endpoint Structure
API Endpoint Structure
Endpoint Types
Web Endpoints (Default)
Full-stack endpoints that render HTML pages and handle form submissions.
Generated Files:
Endpoint classes with HTML rendering
Associated page components
Form handling and validation
Flash messages and redirects
Example:
API Endpoints (--api)
--api)JSON API endpoints for building APIs, mobile backends, or microservices.
Generated Files:
Endpoint classes with JSON responses
Request/response contracts
Status codes and error handling
No HTML templates
Example:
Action Types
Index Action
Lists all resources.
Generated Code:
Route: GET /users
Show Action
Displays a single resource.
Generated Code:
Route: GET /users/:id
New Action
Displays form for creating a new resource.
Generated Code:
Route: GET /users/new
Create Action
Handles form submission to create a new resource.
Generated Code:
Route: POST /users
Edit Action
Displays form for editing an existing resource.
Generated Code:
Route: GET /users/:id/edit
Update Action
Handles form submission to update an existing resource.
Generated Code:
Route: PUT /users/:id or PATCH /users/:id
Destroy Action
Deletes a resource.
Generated Code:
Route: DELETE /users/:id
Examples
Blog Application
API Service
Nested Resources
Generated Code Examples
Web Endpoint (Full CRUD)
API Endpoint
Route Registration
Automatic Route Registration
By default, endpoints are automatically registered in your routes:
Manual Route Registration
If you use --skip-routes, register routes manually:
Testing
Generated Test Files
API Endpoint Tests
Advanced Usage
Custom Endpoint Logic
Nested Resources
API Versioning
Best Practices
1. Naming Conventions
2. API Design
3. Security
4. Testing
Troubleshooting
Endpoint Not Found
Parameter Issues
Template Issues
The endpoint generator creates the HTTP request handlers for your Azu application, providing both web and API endpoints with full CRUD operations.
Next Steps:
Model Generator - Create database models
Contract Generator - Add request validation
Page Generator - Create view templates
Last updated