Just need to specify a format
get '/xml' => sub {
my $self = shift;
my $xml = <<'XML';
<employees>
<employee><id>1001</id><name>John Smith</name></employee>
<employee><id>1002</id><name>Jane Dole</name></employee>
</employees>
XML
$self->render(data => $xml, format => 'xml');
};
Response header equals the following:
Connection: keep-alive
Server: Mojolicious (Perl)
Content-Length: 140
Content-Type: application/xml
Date: Wed, 09 Apr 2014 05:36:05 GMT
200 OK
Could also place the data in a template, of course:
get '/xml' => sub {
my $self = shift;
$self->render('employees', format => 'xml');
};
app->start;
__DATA__
@@ employees.xml.ep
<employees>
<employee><id>1001</id><name>John Smith</name></employee>
<employee><id>1002</id><name>Jane Dole</name></employee>
</employees>