KES777 / mojo

Mojolicious - Perl real-time web framework
http://mojolicio.us
Artistic License 2.0
0 stars 0 forks source link

Content negotiation #36

Open KES777 opened 6 years ago

KES777 commented 6 years ago

Summary

Route default format take precedence over requested format, even Accept header

$ perl -Mojo -E 'a("/" => {format => "txt"} => sub { $_->render(text => $_->accepts("", "json", "txt") . "\n") })->start' get /?format=json
txt

Motivation

By setting up {format} for route:

    get '/route' => { format => 'txt' }

or for an application:

    $app->defaults( format => 'xml' )

we can define supported formats for response:

    get '/route' => { format => [qw(xml json)] }
    $app->defaults ({ format => [qw(xml json)] })

Also this will allow us do content negotiation more accurate. See new format helper