您推荐哪种 Perl RESTful 框架?

发布于 2024-08-10 05:11:42 字数 181 浏览 6 评论 0原文

你好,我正在寻找一个 Perl RESTful 框架,它必须:

  • 在 apache2/mod_perl2 下工作
  • 简单
  • 优雅
  • 轻便
  • 灵活

我只是在做梦还是我可以避免“自己动手”的方法?

您会推荐什么框架?

Hi I'm looking for a Perl RESTful framework that have to :

  • work under apache2/mod_perl2
  • be simple
  • be elegant
  • be light
  • be flexible

Am I just dreaming or can I avoid the 'Roll our own' approach?

What framework would you recommend?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

三寸金莲 2024-08-17 05:11:42

我使用过 舞者 (github)用于我的一些较小的项目。它非常优雅,而且很容易快速完成工作。它的灵感来自 Ruby 框架 Sinatra

这很简单:

#!/usr/bin/env perl
use Dancer;

get '/' => sub {
    'Hello world!'
};

dance;

I've used Dancer (github) for some smaller projects of mine. It's very elegant and very easy to get things done quickly with. It was inspired by the Ruby framework Sinatra.

It's as easy as:

#!/usr/bin/env perl
use Dancer;

get '/' => sub {
    'Hello world!'
};

dance;
虐人心 2024-08-17 05:11:42

如果您查看测试套件,Dancer 的文档非常齐全且值得信赖:约 500 个测试覆盖了超过 80% 的源代码树。

它符合 PSGI/Plack 且几乎没有依赖性。 1.0版本应该很快就会发布(也许这个周末)。

请参阅舞者网站以保持关注。

Dancer is pretty well documented and trustable if you look at the test suite: ~500 tests that cover more than 80% of the source tree.

It's PSGI/Plack compliant and has few dependencies. The version 1.0 should be released very soon (maybe this weekend).

See the dancer website to stay tuned.

夏の忆 2024-08-17 05:11:42

另一个值得考虑的方法是 Mojolicious,它允许以非常简单的方式编写和测试 RESTful API。

Another to consider would be Mojolicious which allows both writing and testing RESTful APIs in a very straightforward way.

从此见与不见 2024-08-17 05:11:42

我想你会发现 Squatting 勾选了所有这些框!

我用它编写了很多小型的 RESTful 应用程序。它非常适合此目的,并且合作非常愉快。

以下是更多链接:

这是一个简单的“你好世界!”示例:

use strict;
use warnings;

{
  package Simple;
  use base 'Squatting';
}

{ 
  package Simple::Controllers;
  use Squatting ':controllers';

  our @C = (
    C(
      Index => [ '/' ],
      get   => sub { 
        my ($self) = @_;
        my $v = $self->v;
        $v->{hello} = 'Hello World!';
        $self->render( 'hello' );
      },
    ),
  );
}

{
  package Simple::Views;
  use Squatting ':views';
  use HTML::AsSubs;

  our @V = (
    V(  'html',

      layout => sub { 
        my ($self, $v, @yield) = @_;
        html(
          head( title('Simple web app') ),
          body( @yield ),
        )->as_HTML;
      },
  
      hello => sub {
        my ($self, $v) = @_;
        p( $v->{hello} );
      },
    ),
  );
}

将上面的内容另存为 Simple.pm 并保存在相关位置,并确保您的 Apache 配置中包含以下内容:

<Perl>
  use Simple 'On::MP20';
  Simple->init
</Perl>

<Location />
  SetHandler perl-script
  PerlHandler Simple->mp20
</Location>

然后就可以开始了!

在这里,我还要顺便提一下其他几个应该符合要求的框架:

我说“顺便提及”是因为我没有使用过其中任何一个,并且我不确定它们是否可以(开箱即用)与 mod_perl2 一起使用。仍然有 PSGI / Plack 就在拐角处,这也不会成为问题长;-)

/I3az/

I think you will find that Squatting ticks all those boxes!

I've written quite a few small RESTful apps with it. Its ideally suited for this and its been a pleasure to work with.

Here are some more links:

Here is a simple "hello world!" example:

use strict;
use warnings;

{
  package Simple;
  use base 'Squatting';
}

{ 
  package Simple::Controllers;
  use Squatting ':controllers';

  our @C = (
    C(
      Index => [ '/' ],
      get   => sub { 
        my ($self) = @_;
        my $v = $self->v;
        $v->{hello} = 'Hello World!';
        $self->render( 'hello' );
      },
    ),
  );
}

{
  package Simple::Views;
  use Squatting ':views';
  use HTML::AsSubs;

  our @V = (
    V(  'html',

      layout => sub { 
        my ($self, $v, @yield) = @_;
        html(
          head( title('Simple web app') ),
          body( @yield ),
        )->as_HTML;
      },
  
      hello => sub {
        my ($self, $v) = @_;
        p( $v->{hello} );
      },
    ),
  );
}

Save above as Simple.pm in relevant place and make sure the following is in your Apache config:

<Perl>
  use Simple 'On::MP20';
  Simple->init
</Perl>

<Location />
  SetHandler perl-script
  PerlHandler Simple->mp20
</Location>

And away you go!

While here I would also give a passing mention to a couple of other frameworks which should fit the bill:

I say "passing mention" because I haven't used either of these and I'm not sure if either work (out of the box) with mod_perl2. Still with PSGI / Plack just around the corner this wouldn't be an issue for too long ;-)

/I3az/

樱娆 2024-08-17 05:11:42

我最喜欢的 Perl Web 应用程序框架是 CGI::Application。它非常轻量级(您可以继承的单个基类),并且执行处理 Web 应用程序编程的重复任务所需的最低限度的工作,否则不会妨碍您。您可以在正式的 MVC 设计中使用它,或者如果您想要的话,可以做一些临时的事情。

它有一个简单的 插件 架构,允许您轻松添加对
模板工具包
HTML::Template 开箱即用)会话
身份验证,
JSON,
流媒体,
等等。

最后,为了创建类似 REST 的友好 URL,有出色的 CGI::Application ::Dispatch,它为您提供了一个强大的基于规则的引擎,用于基于 URL 的调度。

此外,尽管它的名字如此,但它可以在 mod_perl 1 和 2 下无缝工作。

My favorite Perl web application framework is CGI::Application. It is very lightweight (a single base class that you can inherit from) and does the bare minimum necessary to handle the repetitive tasks of web app programming and otherwise stay out of your way. You can use it in a formal MVC design, or do things more ad hoc if that's what you want.

It has a simple plugin architecture, allowing you to easily add support for
Template Toolkit
(HTML::Template is supported out of the box) sessions,
authentication,
JSON,
streaming,
and so on.

Finally, for creating REST-like friendly URLs, there is the excellent CGI::Application::Dispatch, which gives you a powerful rules-based engine for URL-based dispatch.

Also, despite its name, it works seamlessly under mod_perl 1 and 2.

奶茶白久 2024-08-17 05:11:42

Catalyst 是一个 MVC 框架,可以用来制作 Restfull 服务

  • 它运行在 apache2/mod_perl2 下
  • 它很简单优雅,但恕我直言,不如大多数“新”MVC 框架
  • 是的..它很轻。
  • 不要认为它真的很灵活..:(..

编辑:
- 我所说的“新”框架是那些具有良好的测试框架可供使用的框架(例如rails/spring/Seam,使用催化剂除了正常的单元测试之外很难进行测试),并且还有很多开发人员致力于构建应用程序(围绕这些框架的社区更加活跃)。这就是为什么我认为 Catalyst 也不太灵活。

Catalyst is a MVC framework that you can use to make Restfull services

  • It runs under apache2/mod_perl2
  • It is simple and elegant but IMHO not as much as most of the "new" MVC frameworks
  • Yeah .. it is light.
  • Dont think it is really flexible .. :( ..

EDIT:
- The "new" frameworks I said are the ones that have good test frameworks to use (like rails/spring/Seam, with catalyst it is not easy to do tests besides the normal unit tests) and also a lot of developers working to build applications to them (the community around these frameworks are far more active). That's why I dont think Catalyst is really flexible too.

人间☆小暴躁 2024-08-17 05:11:42

我终于推出了自己的纯 mod_perl2 RESTful API 专用框架:
http://code.google.com/p/apache2rest/

没有任何内置内容除了必需品。其余部分是可扩展的(或将会是)。我查看了您的所有建议,它们似乎都解决了太多问题(DBI 管理、ORM、模板引擎、嵌入式服务器...)。

这就是我写这篇文章的原因。我希望你会发现它很有用。

I finally rolled my own pure mod_perl2 RESTful API dedicated framework:
http://code.google.com/p/apache2rest/

Nothing is built-in except the essential. The rest is extensible (or will be). I had a look at all your suggestions, and they all seem to address too many things (DBI management, ORM, template engine, embedded server...).

That's why I wrote this one. I hope you'll find it useful.

季末如歌 2024-08-17 05:11:42

抱歉回答有点晚了,但我在链接文本中描述了一个REST框架这对我来说效果很好。它使得添加新资源变得非常简单;除了特定于资源的业务逻辑外,我几乎不需要编写更多内容;框架会处理剩下的事情。

Sorry about answering a bit late, but I described a REST framework in link text which has worked well for me. It makes adding new resources very simple; I barely have to write more than the resource-specific business logic; the framework takes care of the rest.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文