Swazoo documentationShort presentation Short introduction Short tutorial
Short presentation Short introduction Swazoo is easy after you grasp a few concepts. Let's start with those concepts: - 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.
- SwazooServer singleton: return one and only one server which holds the Sites.
- 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.
- 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 := Site new name: 'test'. "name is just for convinience" site host: 'localhost' ip: '127.0.0.1' port: 8888. 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 Swazoo.Resource, 2. implement (actually override) a method answerTo: aRequest : | response | response := Swazoo.HTTPResponse ok. response entity: '<h1>Hello World!</h1>'. ^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:8888/helloworld.html in your browser.
|