Skip to content

Add $res->json() method for JSON responses#133

Merged
alexander-zierhut merged 1 commit intofeature/asset-proxyfrom
feature/response-json
Apr 21, 2026
Merged

Add $res->json() method for JSON responses#133
alexander-zierhut merged 1 commit intofeature/asset-proxyfrom
feature/response-json

Conversation

@alexander-zierhut
Copy link
Copy Markdown
Contributor

@alexander-zierhut alexander-zierhut commented Apr 21, 2026

Summary

  • Adds a Response::json(mixed \$data, int \$encodingOptions = 0): void helper that sets Content-Type: application/json and emits json_encode(\$data, \$encodingOptions | JSON_THROW_ON_ERROR).
  • Unlike generateRest* helpers, it does not exit and does not wrap in a meta envelope — use it when you need to send a raw JSON body.
  • Throws \JsonException on unencodable values (JSON_THROW_ON_ERROR is always applied).
  • Documents the new method in docs/core-features/rest-api.md and adds a line to Changelog.md under v1.2.0.

Test plan

  • docs/core-features/rest-api.md renders correctly in the docs site.
  • A controller calling \$res->json(['ok' => true]) returns {"ok":true} with Content-Type: application/json and status 200.
  • Passing a non-encodable value (e.g. a resource or a circular reference) raises JsonException.

Merge order

This PR targets feature/asset-proxy. Merge this first, then merge PR #112 into main.

@alexander-zierhut alexander-zierhut added this to the v1.2.0 milestone Apr 21, 2026
@alexander-zierhut alexander-zierhut merged commit 8081366 into feature/asset-proxy Apr 21, 2026
@alexander-zierhut alexander-zierhut deleted the feature/response-json branch April 21, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request #module-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant