Swazoo documentation

Swazoo FAQ

Streaming 

 

Short presentation

Short introduction

Swazoo is easy after you grasp a few concepts. Let's start with those concepts:

  1. Site : Swazoo can serve many sites at once (virtual sites). Class Site is therefore a main class to start configuring your server. It holds an IP, port and hostname of your site.
  2. SwazooServer singleton: return one and only one server which holds the Sites.
  3. Resource is an abstract class for all so called web resources. Such resource has its url address and can serve with responding to web requests. Every resource need to #answerTo: aHTTPRequest with aHTTPResponse. Site is a subclass of a Resource. You can subclass it with your own implementation. There is also a CompositeResource, which can hold many subresources. Site is also aCopmpositeResource and therefore you can add your own resources to your site.
  4. classes HTTPRequest, HTTPResponse should be obvious.

Short tutorial

Here is the simplest recipe possible to make your Swazoo site running. "Doit" from a workspace:

|site|
site := SwazooSite new name: 'test'. "name is just for convenience"
site host: 'localhost' ip: '127.0.0.1' port: 6666.
SwazooServer singleton addSite: site.
site start.

Now you can create your own web resource with url '/helloworld.html' to return a sample Hello World! web page:

1. Make new class MyResource by subclassing SwazooResource,

2. implement (actually override) a method answerTo: aRequest :

| response |
response := Swazoo.HTTPResponse ok.
response entity: '

Hello World!

'.
^response

3. from workspace, make instance of your resource, define its url and add it to your site:

| resource composite |
resource := MyResource new uriPattern: 'helloworld.html'.
composite := CompositeResource new uriPattern: '/'.
composite addResource: resource.
(SwazooServer singleton siteNamed: 'test') addResource: composite.

4. open http://localhost:6666/helloworld.html in your browser.

 



Updated: 27.1.2013