Cataly...t::REST(3pm)

✨ NAME ✨

Catalyst::TraitFor::Request::REST β€” bestie, it's a trait (a role πŸ‘‘) that you slap onto Catalyst::Request, and it gifts your request object a whole lil toolkit of REST methods and attributes. The manual page lives in the perl docs as Cataly...t::REST(3pm) πŸ’…


🌸 SYNOPSIS 🌸

okay so here's the vibe:

if ( $c->request->accepts('application/json') ) {
    ...
}

my $types = $c->request->accepted_content_types();

that's it, that's the whole flex ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

so this is a Moose::Role that gets applied to Catalyst::Request, and what it does is add a few methods onto the request object so writing REST-y code is like… actually pleasant? no cap 🫢

as of right now, every single one of these methods is about content types: the ones the client says it accepts, and the content type that showed up in the request. that's the whole assignment, and it ate. πŸ’–


πŸŽ€ METHODS πŸŽ€

data

if the request went through the Deserializer action, this method hands you back the deserialized data structure. that's it. that's the whole thing. πŸ“

accepted_content_types

returns an array reference of the content types the client accepts. iconic.

this list gets built by peeking at all of these sources:

  • Content-type header β€” if this exists, it will always be the first type in the list. no exceptions, she goes first, main character energy. πŸ‘‘
  • content-type parameter β€” if the request is a GET request and there's a "content-type" parameter chillin' in the query string, this one comes before any of the types in the Accept header. lowkey a sneaky little override. πŸ™ˆ
  • Accept header β€” this gets parsed, and the types it finds get ordered by the relative quality specified for each type. quality matters, bestie. ⭐

and here's the lil rule that ties it together: if a type shows up in more than one of those places, it gets ordered based on where it was first found. first come, first served, periodt. πŸ’…

preferred_content_type

this just returns the first content type it finds. it's shorthand for:

$request->accepted_content_types->[0]

literally just the first one. the chosen one. 🌈

accepts($type)

give it a content type, and it returns true if that type is accepted. slay.

⚠️ okay important caveat, don't skip this: this does not do any wildcard expansion of types. none. zero. wildcards stay wildcards. πŸ’€

🫢 AUTHORS 🫢

for the authors, go look at Catalyst::Action::REST β€” they're all listed over there. ✨


πŸ’œ LICENSE πŸ’œ

you may distribute this code under the same terms as Perl itself. go wild, bestie. 🌸


and that's a wrap!! this page was served up by perl v5.40.1 on 2026-05-07, in the Cataly...t::REST(3pm) era of the perl docs. mwah, take care of her πŸŽ€πŸ’–βœ¨

πŸ“¦ where this page comes from