【问题标题】:REST Server: Mojolicious truncating stash valuesREST 服务器:Mojolicious 截断存储值
【发布时间】:2014-08-28 01:40:36
【问题描述】:

我对 Mojolicious 和创建 REST 服务还很陌生。我正在尝试编写一个 REST 服务来查询资产数据库。

一个示例网址:

http://test.example.com:3000/test/asset/web01.example.local

这被路由到以下逻辑:

get '/test/asset/:node' => sub {
        my $self  = shift;
        my $node = $self->stash('node');
        my $sql = qq {
            SELECT id, name, type, location 
            FROM inventory 
            WHERE name = ?
        };
        my $cursor = $self->db->prepare($sql);
        $cursor->execute($node,$node);
        my $record = $cursor->fetchrow_hashref;
        $cursor->finish;
        $self->db_disconnect;

        say $self->stash('node');
        return $self->render(json => $record);
};

“say”语句表明 .example.local 正在被截断:


[Wed Aug 27 21:24:05 2014] [debug] GET "/test/asset/web01.example.local".
[Wed Aug 27 21:24:05 2014] [debug] Routing to a callback. 
web01
[Wed Aug 27 21:24:05 2014] [debug] 200 OK (0.004076s, 245.339/s).

如何让我的服务接受包含点的字符串?如果这是不可能的,我可以使用 GET 请求并传递 FQDN(我可以用来查询 2 个独立数据库的唯一方法)并返回结果的方法是什么?

【问题讨论】:

    标签: perl rest mojolicious


    【解决方案1】:

    我认为您必须将占位符的类型从 generic 更改为 relaxed

    get '/test/asset/*node' => sub {
       # your sub continues here ...
    

    另请参阅Mojolicious Guide Routing

    【讨论】:

    • 我正在研究 Mojo 并查看 Controller 模块,因为那是 stash 模块所在的位置。感谢您的信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-16
    • 2018-10-09
    • 1970-01-01
    • 1970-01-01
    • 2019-02-03
    • 2013-07-08
    • 1970-01-01
    相关资源
    最近更新 更多