Mojolicious-Plugin-Restify

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  sub read {
    my $c = shift;
 
    # account was placed in the stash in the resource_lookup action
    $c->render(json => $c->stash('account'));
  }
 
  sub patch { ... }
 
  sub update { ... }
 
  1;
```
 
is a [Mojolicious::Plugin](https://metacpan.org/pod/Mojolicious::Plugin). It
simplifies generating all of the
typical REST *collection* endpoint (e.g., `/accounts` or `/invoices>` and maps
the common HTTP verbs (`DELETE`, `GET`, `PATCH`, `POST`, `PUT>` to underlying

lib/Mojolicious/Plugin/Restify.pm  view on Meta::CPAN

324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
  sub read {
    my $c = shift;
 
    # account was placed in the stash in the resource_lookup action
    $c->render(json => $c->stash('account'));
  }
 
  sub patch { ... }
 
  sub update { ... }
 
  1;
 
=head1 DESCRIPTION
 
L<Mojolicious::Plugin::Restify> is a L<Mojolicious::Plugin>. It simplifies
generating all of the L<Mojolicious::Routes> for a typical REST I<collection>
endpoint (e.g., C</accounts> or C</invoices>) and maps the common HTTP verbs
(C<DELETE>, C<GET>, C<PATCH>, C<POST>, C<PUT>) to underlying controller class
methods.

t/restify.t  view on Meta::CPAN

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  my ($self, $msg) = @_;
  my $id = $self->stash($self->name . '_id') // '';
  $self->render(text => "$msg,$id");
}
 
sub resource_lookup {1}
sub create          { shift->catchall('create') }
sub delete          { shift->catchall('delete') }
sub list            { shift->catchall('list') }
sub read            { shift->catchall('read') }
sub update          { shift->catchall('update') }
 
sub name {
  my $self = shift;
  my $name = $self->stash->{controller};
  $name =~ s,^.*\-,,;
  return $name;
}
 
1;

t/synopsis.t  view on Meta::CPAN

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  my ($self, $msg) = @_;
  my $id = $self->stash($self->name . '_id') // '';
  $self->render(text => "$msg,$id");
}
 
sub resource_lookup {1}
sub create          { shift->catchall('create') }
sub delete          { shift->catchall('delete') }
sub list            { shift->catchall('list') }
sub read            { shift->catchall('read') }
sub update          { shift->catchall('update') }
 
sub name {
  my $self = shift;
  my $name = $self->stash->{controller};
  $name =~ s,^.*?\-,,;
  return $name;
}
 
1;



( run in 0.314 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )