Skip to content

Commit

Permalink
added a little more HATEOAS to the routing guide
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 2, 2013
1 parent 966d6e3 commit 12a1e59
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,6 +1,6 @@

4.11 2013-06-02
- Added append method to Mojo::Headers.
- Added allow and append methods to Mojo::Headers.
- Added split_header function to Mojo::Util.
- Fixed small quality detection bug in Mojolicious::Types.
- Fixed a few small boundary and charset detection bugs in Mojo::Content.
Expand Down
9 changes: 8 additions & 1 deletion lib/Mojo/Headers.pm
Expand Up @@ -8,7 +8,7 @@ has max_line_size => sub { $ENV{MOJO_MAX_LINE_SIZE} || 10240 };
# Common headers
my @HEADERS = (
qw(Accept Accept-Charset Accept-Encoding Accept-Language Accept-Ranges),
qw(Authorization Cache-Control Connection Content-Disposition),
qw(Allow Authorization Cache-Control Connection Content-Disposition),
qw(Content-Encoding Content-Length Content-Range Content-Type Cookie DNT),
qw(Date ETag Expect Expires Host If-Modified-Since Last-Modified Link),
qw(Location Origin Proxy-Authenticate Proxy-Authorization Range),
Expand Down Expand Up @@ -240,6 +240,13 @@ Shortcut for the C<Accept-Ranges> header.
Add one or more header values with one or more lines.
=head2 allow
my $allow = $headers->allow;
$headers = $headers->allow('GET, POST');
Shortcut for the C<Allow> header.
=head2 append
$headers = $headers->append(Vary => 'Accept-Encoding');
Expand Down
12 changes: 10 additions & 2 deletions lib/Mojolicious/Guides/Routing.pod
Expand Up @@ -664,11 +664,19 @@ You can also add your own shortcuts to make route generation more expressive.
# Handle GET requests
$resource->get->to('#show')->name("show_$name");

# Handle OPTIONS requests
$resource->options(sub {
my $self = shift;
$self->res->headers->allow('GET, POST');
$self->render(data => '', status => 204);
});

return $resource;
});

# POST /user -> {controller => 'user', action => 'create'}
# GET /user -> {controller => 'user', action => 'show'}
# POST /user -> {controller => 'user', action => 'create'}
# GET /user -> {controller => 'user', action => 'show'}
# OPTIONS /user
$r->resource('user');

Shortcuts can lead to anything, routes, bridges or maybe even both. And watch
Expand Down
1 change: 1 addition & 0 deletions t/mojo/headers.t
Expand Up @@ -50,6 +50,7 @@ is $headers->accept_charset('foo')->accept_charset, 'foo', 'right value';
is $headers->accept_encoding('foo')->accept_encoding, 'foo', 'right value';
is $headers->accept_language('foo')->accept_language, 'foo', 'right value';
is $headers->accept_ranges('foo')->accept_ranges, 'foo', 'right value';
is $headers->allow('foo')->allow, 'foo', 'right value';
is $headers->authorization('foo')->authorization, 'foo', 'right value';
is $headers->connection('foo')->connection, 'foo', 'right value';
is $headers->cache_control('foo')->cache_control, 'foo', 'right value';
Expand Down

0 comments on commit 12a1e59

Please sign in to comment.