Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microframeworks for Squeak/Pharo web service

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?

like image 237
Benjamin Pollack Avatar asked Dec 22 '10 20:12

Benjamin Pollack


4 Answers

"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
like image 69
Sean DeNigris Avatar answered Sep 30 '22 17:09

Sean DeNigris


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.

like image 22
vmusulainen Avatar answered Sep 30 '22 16:09

vmusulainen


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:

  • http://ss3.gemstone.com/ss/RatPack.html
  • https://github.com/timfel/ratpack

This information comes from a similar question I posted recently.

like image 27
Sebastian N. Avatar answered Sep 30 '22 15:09

Sebastian N.


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.

like image 42
Janko Mivšek Avatar answered Sep 30 '22 16:09

Janko Mivšek