View on
perlancar > Perinci-Access-HTTP-Server-0.60 > Plack::Middleware::PeriAHS::ParseRequest



Annotate this POD



Open  0
View/Report Bugs
Module Version: 0.60   Source  


Plack::Middleware::PeriAHS::ParseRequest - Parse Riap request from HTTP request


This document describes version 0.60 of Plack::Middleware::PeriAHS::ParseRequest (from Perl distribution Perinci-Access-HTTP-Server), released on 2016-03-16.


 # in your app.psgi
 use Plack::Builder;

 builder {
     enable "PeriAHS::ParseRequest",
         match_uri => m!^/api(?<uri>/[^?]*)!;


This middleware's task is to parse Riap request from HTTP request (PSGI environment) and should normally be the first middleware put in the stack.

Parsing result

The result of parsing will be put in $env->{"riap.request"} hashref.

Aside from that, this middleware also sets these for convenience of later middlewares:

Parsing process

From HTTP header and request body. First parsing is done as per Riap::HTTP specification's requirement. All X-Riap-* request headers are parsed for Riap request key. When an unknown header is found, HTTP 400 error is returned. Then, request body is read for args. application/json document type is accepted, and also text/yaml (if accept_yaml configuration is enabled).

Additionally, the following are also done:

From URI. Request URI is checked against match_uri configuration (This step will be skipped if match_uri configuration is not set or empty). If URI doesn't match this regex, a 404 error response is returned. It is a convenient way to check for valid URLs as well as set Riap request keys, like:


The default match_uri is qr/(?<uri>[^?]*)/.

From form variables. If parse_form configuration is enabled, args request key will be set (or added) from GET/POST request variables, for example: http://host/api/foo/bar?a=1&b:j=[2] will set arguments a and b (":j" suffix means value is JSON-encoded; ":y" is also accepted if the accept_yaml configurations are enabled). In addition, request variables -riap-* are also accepted for setting other Riap request keys. Unknown Riap request key or encoding suffix will result in 400 error.

If request format is JSON and form variable callback is defined, then it is assumed to specify callback for JSONP instead part of args. "callback(json)" will be returned instead of just "json".

From form variables (2, ReForm). PeriAHS has support for ReForm. If parse_reform configuration is set to true and form variable -submit is also set to true, then the resulting args from previous step will be further fed to ReForm object. See the "parse_reform" in the configuration documentation.

From URI (2, path info). If parse_path_info configuration is enabled, and uri Riap request key has been set (so metadata can be retrieved), args will be set (or added) from URI path info. See "parse_path_info" in the configuration documentation.


will result in ['a1', 'a2', 'a3'] being fed into Perinci::Sub::GetArgs::Array. An unsuccessful parsing will result in HTTP 400 error.



Please visit the project's homepage at


Source repository is at


Please report any bugs or feature requests on the bugtracker website

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.




perlancar <>


This software is copyright (c) 2016 by

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: