Bug 13799: RESTful API with Mojolicious and Swagger2
[koha.git] / Koha / REST / V1.pm
1 package Koha::REST::V1;
2
3 use Modern::Perl;
4 use Mojo::Base 'Mojolicious';
5
6 sub startup {
7     my $self = shift;
8
9     my $route = $self->routes->under->to(
10         cb => sub {
11             my $c = shift;
12             my $user = $c->param('user');
13             # Do the authentication stuff here...
14             $c->stash('user', $user);
15             return 1;
16         }
17     );
18
19     # Force charset=utf8 in Content-Type header for JSON responses
20     $self->types->type(json => 'application/json; charset=utf8');
21
22     $self->plugin(Swagger2 => {
23         route => $route,
24         url => $self->home->rel_file("api/v1/swagger.json"),
25     });
26 }
27
28 1;