https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44038 Bug ID: 44038 Summary: Decide how controllers read request bodies: $c->payload versus $c->req->json Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: REST API Assignee: koha-bugs@lists.koha-community.org Reporter: martin.renvoize@openfifth.co.uk QA Contact: tomascohen@gmail.com CC: tomascohen@gmail.com Target Milestone: --- Bug 44035 adds a $c->payload helper to the REST API. It returns the request body as a Perl structure whatever format the client sent it in (JSON or XML to start with), as accepted by the route's consumes. It is the structure that was validated against the body schema, coerced to the types the schema declares. Controllers today call $c->req->json for the body, in well over a hundred places. That keeps working and does not need to change for routes that only consume JSON: nothing is lost by leaving them alone. This bug is to decide, and then record, how we want controllers to read the request body going forward: - Routes that consume more than one format must use $c->payload, as $c->req->json would only be right for one of them. - For JSON-only routes, should we keep $c->req->json, or move to $c->payload for consistency so that adding a format to a route never needs a controller change? - If we do migrate, should it be done in one sweep, opportunistically as controllers are touched, or only enforced for new code through the coding guidelines and a QA check? There is no urgency, and it can reasonably end as a coding guidelines update with no code change. Moving to $c->payload has the advantage that the controller then gets the validated and coerced structure, instead of the raw parse that $c->req->json returns. Follow-up to bug 44035. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.