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