1
|
1 |
# README #
|
|
2 |
|
|
3 |
### What's this? ###
|
|
4 |
|
|
5 |
This module implements a basic framework for interacting with the
|
|
6 |
Mongrel2 webserver. (http://mongrel2.org).
|
|
7 |
|
|
8 |
|
|
9 |
### Installation ###
|
|
10 |
|
|
11 |
The easiest way to install this module is via the nimble package manager,
|
|
12 |
by simply running 'nimble install mongrel2'.
|
|
13 |
|
|
14 |
Alternatively, you can fetch the 'mongrel2.nim' file yourself, and put it in a place of your choosing.
|
|
15 |
|
|
16 |
### Usage ###
|
|
17 |
|
|
18 |
The "bare minimum" required for testing your Mongrel2 configuration is
|
|
19 |
nearly a one-liner.
|
|
20 |
|
|
21 |
```
|
|
22 |
#!nimrod
|
|
23 |
import mongrel2
|
|
24 |
newM2Handler( "app-id", "tcp://127.0.0.1:9009", "tcp://127.0.0.1:9008" ).run
|
|
25 |
```
|
|
26 |
|
|
27 |
Assuming your Mongrel2 server is configured correctly, you should be
|
|
28 |
able to steer a browser to your handler to see a helpful message.
|
|
29 |
|
|
30 |
To do anything more complex, you'll want to look at the module
|
|
31 |
documentation. Here's a "hello world":
|
|
32 |
|
|
33 |
```
|
|
34 |
#!nimrod
|
|
35 |
let handler = newM2Handler( "app-id", "tcp://127.0.0.1:9009", "tcp://127.0.0.1:9008" )
|
|
36 |
|
|
37 |
proc hello_world( request: M2Request ): M2Response =
|
|
38 |
result = request.response
|
|
39 |
result[ "Content-Type" ] = "text/plain"
|
|
40 |
result.body = "Hello there, world!"
|
|
41 |
result.status = HTTP_OK
|
|
42 |
|
|
43 |
handler.action = hello_world
|
|
44 |
handler.run
|
|
45 |
```
|
|
46 |
|
|
47 |
This module would be suitable to build a more elaborate framework
|
|
48 |
around, such as Ruby's "Strelka" (https://github.com/ged/strelka). I
|
|
49 |
may eventually look into integration with Jasper, as well.
|
|
50 |
|