Microframeworks for Squeak/Pharo web service

妖精的绣舞 提交于 2019-12-03 16:00:35
Sebastian N.

I would like to share what I think is more up-to-date information (as of end of 2012).

Zinc Components

Currently in Pharo 1.4/2.0 the de-facto standard for HTTP client/server seems to be the Zinc HTTP Components. And the latest Seaside version (3.0) switched to Zinc as well.

You can of course use Zinc directly to implement web-services or serve web-pages.

Take a look particularly at classes ZnServer and search for classes like Zn*Delegate (like ZnDefaultServerDelegate or ZnStaticFileServerDelegate)

Seaside REST

Latest versions of Seaside include support for RESTful web-services. This can be used to implement web-services or serve web-pages. It's pretty straightforward.

For more information look at the "REST Services" chapter of the online Seaside book. This chapter centers about implementing web-services, but it works for web-pages as well.

Ratpack

I have also been told about Ratpack, a sinatra-like web-framework developed by Tim Felgentreff. There are two repositories. I think the github one is more recent. See here:

This information comes from a similar question I posted recently.

"In this particular case, I literally have three URLs that need to do stuff via HTTP POST; that's it."

For really simple cases, you can just register with (or subclass) Kom's HttpService like so (from the class comment, see for more info/options):

    (HttpService on: 8080 named: 'Example Http Service')
    onRequestDo: [ :httpRequest | SomeGlobal processRequest: httpRequest ];
    start

You can also use teapot. Teapot is micro web framework on top of the Zinc HTTP components, that focuses on simplicity and ease of use. It's under 500 lines of code, not counting the tests.

Teapot on
    GET: '/hi' -> 'Bonjour!';
    GET: '/hi/<user>' -> [:req | 'Hello ', (req at: #user)];
    GET: '/say/hi/*' -> (Send message: #greet: to: greeter);
    start.

(ZnEasy get: 'http://localhost:1701/hi/user1') entity string. "Hello user1"

There are available mustache templates, output transformers, before filters. The framework is well documented.

You can subclass a SwazooSite in Swazoo for such a micro website, but I think you will soon end needing more functionality, so starting directly on one of those three frameworks are better bet long-term.

That they are heavy is maybe just an impression and lack of better documentation of usage for such simple websites. Also, if you look at the framework as blackbox, which is complex internally but simple externally, then I'd say all Smalltalk web frameworks are quite simple comparing to other web frameworks.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!