Cataly...owsers(3pm)
π NAME π
Catalyst::TraitFor::Request::REST::ForBrowsers β a request trait that's giving REST and browser energy at the same time β¨
So like, this is Catalyst::TraitFor::Request::REST::ForBrowsers, and it lives in the Perl module manual pages (section 3pm, iykyk). It's a request trait. It handles REST. It handles browsers. It's doing both. Obsessed. π«Ά
πΈ SYNOPSIS πΈ
package MyApp;
use Moose;
use namespace::autoclean;
use Catalyst;
use CatalystX::RoleApplicator;
extends 'Catalyst';
__PACKAGE__->apply_request_class_roles(qw[
Catalyst::TraitFor::Request::REST::ForBrowsers
]);
Like, that's it. That's the whole setup. Slap it on with apply_request_class_roles and you're literally done bestie π
π¦ DESCRIPTION π¦
Writing REST-y apps? Iconic. Correct. Main character behavior. But the way that you also gotta support web browsersβ¦ π and browsers are not it. So you end up needing some hackish workarounds. And this module? This module is the workarounds. It provides them. For you. No cap.
Specifically, it lets you do two things:
- It lets you "tunnel"
PUTandDELETErequests across aPOST, because most browsers do not supportPUTorDELETEactions (as of early 2009, at least β and honestly bestie, early 2009 was a while ago). - It provides a heuristic to check if the client is a web browser, regardless of what content types it claims to accept. Why do we need this? Because a browser might claim it accepts the
application/xmlcontent type, but it's really not going to do anything useful with it, and you're best off giving it HTML. Like girl, be so serious rn. π
π METHODS π
This class provides the following methods:
β $request->method
This method works just like Catalyst::Request->method() except it allows for tunneling of PUT and DELETE requests via a POST.
Specifically, you can provide a form element named x-tunneled-method which can override the request method for a POST. This only works for a POST, not a GET. (Read that again. It only works for a POST. Not a GET. Periodt.)
You can also use a header named x-http-method-override instead (Google uses this header for its APIs). Fancy π
β $request->looks_like_browser
This attribute provides a heuristic to determine whether or not the request appears to come from a browser. You can use this however you want. I usually use it to determine whether or not to give the client a full HTML page or some sort of serialized data.
This is a heuristic, and like any heuristic, it is probably wrong sometimes. Here is how it works:
- If the request includes a header
X-Request-Withset to eitherHTTP.RequestorXMLHttpRequest, this returns false. The assumption is that if you're doing XHR, you don't want the request treated as if it comes from a browser. Makes sense honestly. - If the client makes a
GETrequest with a query string parametercontent-type, and that type is not an HTML type, it is not a browser. - If the client provides an Accept header which includes
*/*as an accepted content type, the client is a browser. Specifically, it is IE7, which submits an Accept header of*/*. IE7's Accept header does not include any html types liketext/html. (Not IE7 catching a stray π) - If the client provides an Accept header and accepts either
text/htmlorapplication/xhtml+xmlit is a browser. - If it provides an Accept header of any sort that doesn't match one of the above criteria, it is not a browser.
- The default is that the client is a browser.
β οΈ This all works well for my apps, but read it carefully to make sure it meets your expectations before using it. Do not skip this part bestie, fr fr. Read it. Carefully. π
π AUTHOR π
Dave Rolsky, <autarch@urth.org>
π BUGS π
Please report any bugs or feature requests to bug-catalyst-action-rest@rt.cpan.org, or through the web interface at <http://rt.cpan.org>. We will be notified, and then you'll automatically be notified of progress on your bug as I make changes. Bestie, the whole system is automated, you literally cannot miss the updates π
π COPYRIGHT & LICENSE π
Copyright 2008-2010 Dave Rolsky, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Okay so that's the whole page!! πΈ This was Cataly...owsers(3pm) from the User Contributed Perl Documentation, and the footer energy was perl v5.40.1, dated 2026-05-07. Slay. Go tunnel your PUTs. π
β¨
π¦ where this page comes from
- ubuntu stonking: libcatalyst-action-rest-perl 1.22-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms