Perl Catalyst Controller 链

标签 perl endpoint chaining catalyst

我在创建“灵活”端点时遇到问题。是否有可能沿着这些方向:

# 1) List all Microarrays for this species
/regulatory/species/:species/microarray
sub microarray_list: Chained('species') PathPart('microarray') ActionClass('REST') { }

# 2) Information about a specific array
/regulatory/species/:species/microarray/:microarray
sub microarray_single: Chained('species') PathPart('microarray') CaptureArgs(1) ActionClass('REST') { }

# 3) Information about a probe on the array
/regulatory/species/:species/microarray/:microarray/probe/:probe
sub microarray_probe: Chained('microarray_single') PathPart('probe') Args(1) ActionClass('REST')

启动时 1) 未注册:

| /regulatory/species/*/id/*          | /regulatory/species (1)              |
|                                     | => /regulatory/id (1)                |
| /regulatory/species/*/microarray    | /regulatory/species (1)              |
|                                     | => /regulatory/microarray_list (...) |
| /regulatory/species/*/microarray/*- | /regulatory/species (1)              |
| /probe/*                            | 

任何帮助都将不胜感激!

最佳答案

是的,有可能,您的问题只是您没有 microarray_single 的端点。你可能想要

sub microarray_list :Chained('species') PathPart('microarray')
                     ActionClass('REST') { }

# this is the chain midpoint, it can load the microarray for the endpoints to use
sub microarray :Chained('species') PathPart('microarray')
                CaptureArgs(1) { }

# this is an endpoint with the same path as the midpoint it chains off of
sub microarray_single :Chained('microarray') PathPart('')
                       Args(0) ActionClass('REST') { }

# and this is an endpoint that adds .../probe/*
sub microarray_probe :Chained('microarray') PathPart('probe')
                      Args(1) ActionClass('REST') { }

如果 .../microarray/*/probe/* 之后还有其他事情,那么您也可以这样做,将 microarray_probeArgs 更改为(1) ActionClass('REST') (endpoint) to CaptureArgs(1),然后用:Chained('microarray_probe') PathPart('') 添加一个端点Args(0) ActionClass('REST') 处理没有额外路径部分的情况。

要牢记的重要一点是,只有链 端点(即没有 CaptureArgs 的操作)对应于有效的 URL 路径。

关于Perl Catalyst Controller 链,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42433554/

相关文章:

perl 仅在可用时可选地加载模块

java - 使用 WSO2 ESB 发送简单的电子邮件

java - 具有原生 @WebService 支持的可嵌入 Web 服务器,作为 Endpoint.publish 的替代方案

c++ - 需要使上下文可用于 C++ ostream 插入运算符

http - Angular2 - 如何在组件中链接异步服务调用(http 请求)?

html - 在 Perl 中将 DD/MM/YYYY 转换为 YYYY-MM-DD

perl - 是否可以在使用脚本创建 SVG 之前确定文本字符串的(像素)宽度

multithreading - 在独立 Perl 脚本中使用 Mojo::Promise

python - 处理Flask路由中的所有异常

jQuery 访问刚刚添加的 DOM