ワンクリックで
wheels-api-generator
// Generate RESTful API controllers with JSON responses, proper HTTP status codes, and API authentication. Use when creating API endpoints, JSON APIs, or web services. Ensures proper REST conventions and error handling.
// Generate RESTful API controllers with JSON responses, proper HTTP status codes, and API authentication. Use when creating API endpoints, JSON APIs, or web services. Ensures proper REST conventions and error handling.
| name | Wheels API Generator |
| description | Generate RESTful API controllers with JSON responses, proper HTTP status codes, and API authentication. Use when creating API endpoints, JSON APIs, or web services. Ensures proper REST conventions and error handling. |
Activate when:
component extends="Controller" {
function config() {
provides("json");
verifies(only="show,update,delete", params="key", paramsTypes="integer");
filters(through="requireApiAuth");
}
function index() {
resources = model("Resource").findAll(order="createdAt DESC");
renderWith(
data=resources,
format="json",
status=200
);
}
function show() {
resource = model("Resource").findByKey(key=params.key);
if (!isObject(resource)) {
renderWith(
data={error="Resource not found"},
format="json",
status=404
);
return;
}
renderWith(
data=resource,
format="json",
status=200
);
}
function create() {
resource = model("Resource").new(params.resource);
if (resource.save()) {
renderWith(
data=resource,
format="json",
status=201,
location=urlFor(action="show", key=resource.key())
);
} else {
renderWith(
data={errors=resource.allErrors()},
format="json",
status=422
);
}
}
function update() {
resource = model("Resource").findByKey(key=params.key);
if (!isObject(resource)) {
renderWith(data={error="Not found"}, format="json", status=404);
return;
}
if (resource.update(params.resource)) {
renderWith(data=resource, format="json", status=200);
} else {
renderWith(data={errors=resource.allErrors()}, format="json", status=422);
}
}
function delete() {
resource = model("Resource").findByKey(key=params.key);
if (!isObject(resource)) {
renderWith(data={error="Not found"}, format="json", status=404);
return;
}
resource.delete();
renderWith(data={message="Deleted"}, format="json", status=204);
}
private function requireApiAuth() {
var headers = getHTTPRequestData().headers;
if (!structKeyExists(headers, "Authorization")) {
renderWith(data={error="Unauthorized"}, format="json", status=401);
abort;
}
// Validate API token
var token = replace(headers.Authorization, "Bearer ", "");
if (!isValidApiToken(token)) {
renderWith(data={error="Invalid token"}, format="json", status=401);
abort;
}
}
private boolean function isValidApiToken(required string token) {
// Token validation logic
return true;
}
}
Generated by: Wheels API Generator Skill v1.0
Automatically detect and prevent common Wheels framework errors before code is generated. This skill activates during ANY Wheels code generation (models, controllers, views, migrations) to validate patterns and prevent known issues. Scans for mixed arguments, query/array confusion, non-existent helpers, and database-specific SQL.
Generate authentication system with user model, sessions controller, and password hashing. Use when implementing user authentication, login/logout, or session management. Provides secure authentication patterns and bcrypt support.
Generate Wheels MVC controllers with CRUD actions, filters, parameter verification, and proper rendering. Use when creating or modifying controllers, adding actions, implementing filters for authentication/authorization, handling form submissions, or rendering views/JSON. Ensures proper Wheels conventions and prevents common controller errors.
Troubleshoot common Wheels errors and provide debugging guidance. Use when encountering errors, exceptions, or unexpected behavior. Provides error analysis, common solutions, and debugging strategies for Wheels applications.
Configure Wheels applications for production deployment with security hardening, performance optimization, and environment-specific settings. Use when preparing for production, configuring servers, or hardening security.
Generate documentation comments, README files, and API documentation for Wheels applications. Use when documenting code, creating project READMEs, or generating API docs.