Dancer...::REST(3pm)
β¨ NAME β¨
Dancer::Plugin::REST β a plugin for writing RESTful apps with Dancer, and it's genuinely so good π
This is the manual page for Dancer...::REST (the 3pm kind β a Perl module doc, iykyk).
πΈ VERSION πΈ
version 0.12
π DESCRIPTION π
Okay so, this plugin helps you write a RESTful webservice with Dancer. That's the whole vibe. It's giving "your API but make it effortless" β¨
π¦ SYNOPSYS π¦
(no, bestie, that's not a typo, that's literally what it says, and we respect it π)
package MyWebService;
use Dancer;
use Dancer::Plugin::REST;
prepare_serializer_for_format;
get '/user/:id.:format' => sub {
User->find(params->{id});
};
# curl http://mywebservice/user/42.json
{ "id": 42, "name": "John Foo", email: "john.foo@example.com"}
# curl http://mywebservice/user/42.yml
--
id: 42
name: "John Foo"
email: "john.foo@example.com"
Look at that. One route, two formats, zero stress. main character energy fr fr π
π KEYWORDS π
π« prepare_serializer_for_format
When this pragma is used, a before filter is set by the plugin to automatically change the serializer when a format is detected in the URI. So like, you don't gotta do it yourself. It just happens. Slay.
That means that each route you define with a :format token will trigger a serializer definition, if the format is known.
This lets you define all the REST actions you like as regular Dancer route handlers, without explicitly handling the outgoing data format. Which is the dream, honestly π«Ά
π« resource
This keyword lets you declare a resource your application will handle.
resource user =>
get => sub { # return user where id = params->{id} },
create => sub { # create a new user with params->{user} },
delete => sub { # delete user where id = params->{id} },
update => sub { # update user with params->{user} };
# this defines the following routes:
# GET /user/:id
# GET /user/:id.:format
# POST /user
# POST /user.:format
# DELETE /user/:id
# DELETE /user/:id.:format
# PUT /user/:id
# PUT /user/:id.:format
Eight routes from one little declaration block. ATE. no crumbs. periodt. π₯
π« helpers
Some helpers are available. This helper will set an appropriate HTTP status for you. Because doing it manually is lowkey exhausting and we don't do that here π
β status_ok
status_ok({users => {...}});
Set the HTTP status to 200
β status_created
status_created({users => {...}});
Set the HTTP status to 201
β status_accepted
status_accepted({users => {...}});
Set the HTTP status to 202
β status_bad_request
status_bad_request("user foo can't be found");
Set the HTTP status to 400. This function as for argument a scalar that will be used under the key error. π¨
β status_not_found
status_not_found("users doesn't exists");
Set the HTTP status to 404. This function as for argument a scalar that will be used under the key error. π¨
π LICENCE π
This module is released under the same terms as Perl itself. π
π AUTHORS π
This module has been written by Alexis Sukrieh "<sukria@sukria.net>" and Franck Cuny.
π SEE ALSO π
π AUTHORS π
(yes, again, they said it twice, and honestly? iconic)
- Alexis Sukrieh
<sukria@sukria.net> - Franck Cuny
<franckc@cpan.org>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2026 by Alexis Sukrieh.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
okay that's the whole page bestie, go build something cute with it π§
perl v5.40.1 Β· 2026-02-01 Β· Dancer...::REST(3pm) β mwah, love u, bye πβ¨
π¦ where this page comes from
- ubuntu resolute: libdancer-plugin-rest-perl 0.12-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdancer-plugin-rest-perl 0.12-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