Controllers, validation, and responses

Follow the existing config handler from request input to a response you can diagnose.

A controller validates input, invokes business logic, and returns a response. Keep reusable rules in the owning feature. The config read below shows how one handler returns data, invalid input, or a missing record.

Trace an existing handler

A Service route points to a controller function through its handler. The public config route GET /_/public/config/get calls getConfig. It validates its input with ctx.parse(configValidator.query, ctx.query, "query"), obtains the config capability from ctx.app.config(), and returns publicly readable data through ctx.json(...).

Where the work belongs Example
Validator Define the format of the query parameter key
Controller Read input, invoke the capability, and map a missing record to 404
Business capability Look up a publicly readable config record
Transport Turn the result into an HTTP response

Verify errors and success

Send this request to a running public site, using your Service Origin port.

curl -i 'http://localhost:3000/_/public/config/get'

Omitting key produces 400 with invalid_input and identifies query as the invalid input source. Add the key of a test record already marked public and check the response’s data. Try a valid-looking key for a missing record and expect 404 with config_not_found. Use meta.requestId to correlate the response with Service logs.

For a new controller, choose the route audience, then choose query, body, or files as the input source. Put reusable business operations in the owning context. Exercise invalid input, a missing record, and an access denial separately. Routing · Authentication and authorization

For client input shapes, files, and streaming results, see the HTTP request and response contract.