Microframeworks for Squeak/Pharo web service
Asked Answered
E

4

5

Lots of languages have microframeworks for writing very tiny websites or web services, such as Flask for Python, or Sinatra for Ruby. On Squeak, there doesn't seem to be any equivalent; Iliad, Seaside, and AIDA are all very heavy for just having a little service. What's the preferred way to accomplish this? Directly injecting a hanlder into Comanche or Swazoo?

Epifocal answered 22/12, 2010 at 20:18 Comment(1)
I posted a similar question hereFlavius
F
3

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.

Flavius answered 3/12, 2012 at 21:3 Comment(0)
S
6

"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
Significs answered 22/12, 2010 at 22:1 Comment(0)
L
5

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.

Lithometeor answered 1/12, 2014 at 5:30 Comment(0)
F
3

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.

Flavius answered 3/12, 2012 at 21:3 Comment(0)
A
2

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.

Address answered 22/12, 2010 at 20:37 Comment(2)
In this particular case, I literally have three URLs that need to do stuff via HTTP POST; that's it. It won't ever grow, because it's just fielding three different web hooks and feeding them into HipChat. It's not that I can't use Seaside or AIDA--I know I can--it's just that it seems somewhat silly to drag in e.g. AIDA's whole sites framework just to have three dinky 20-line handlers.Epifocal
If you don't have complex HTML to generate for response, then subclassing SwazooSite would be easier to do. See SwazooDemoSite (in latest beta) for example, and SwazooServer>>prepareDemoSite for hints, how to do such a simple websiteInfamous

© 2022 - 2024 — McMap. All rights reserved.