This egg provides an API for writing Mongrel2 handlers. Mongrel2 strives to be an application, language, and network architecture agnostic web server. The server itself is written in C and is required to actually put handlers created with this egg to use. Mongrel2 communicates with its handlers via ZeroMQ.

The API comes in two flavors: mongrel2-lolevel which is modeled after the Python example handler code of the distribution (see examples/python in the Mongrel2 tarball) and mongrel2 which is built on top of that and modeled after spiffy's API.

Creates and connects two zmq sockets for communicating with a Mongrel2 server. The id is used as the PUB socket's identity and request-endpoint is a zmq endpoint string for that socket to connect to. Correspondingly, request-endpoint is the zmq endpoint string for the PULL socket to connect to. Optionally, an identity for that socket can be given as request-id. The return value is an opaque connection record which is further referred to as a connection.

[procedure](receive-request connection)

Receives a request from connection. This will block the current thread until a request is available. Requests are returned in the form of a record which can be inspected with several procedures also available in this module.

[procedure](request-disconnect? request)

Checks whether the given request signifies a disconnect event.

[procedure](request-sender request)

Returns the given request's sender UUID as a string.

[procedure](request-path request)

Returns the given request's URI path as a string.

[procedure](request-headers request)

Returns the given request's headers as an alist with the keys begin symbols.

[procedure](request-header name request)

Return the value of request's header name which must be a symbol. If there no header of that name is found, #f is returned.

[procedure](request-method request)

Returns the given request's method as a symbol, e.g. JSON or GET.

[procedure](request-body request)

Returns the given request's body as a string.

[procedure](request-data request)

Returns the given request's body in a structured format. This depends on the request's method. Currently it will only handle requests of the type JSON and return the body's contents parsed by the json egg.

[procedure](request-id request)

Returns the given request's listener id as a string.

[procedure](request-type)

Returns the given request's type as a symbol. This is either json, xml or http.

Sends an HTTP response for the given request. The arguments are exactly the same as those of spiffy's send-response with the addition of the keyword argument response which can be used to pass in an intarweb response record to be used as a basis (default is an empty response record).

The current Mongrel2 request record (see the mongrel2-lolevel module for available accessors).

[parameter](current-http-request [http-request])

If the current-request's request-type is http, this parameter holds a corresponding intarweb request record. Otherwise it will be #f.

[parameter](current-http-response [http-response])

If the current-request's request-type is http, this parameter holds an intarweb response record which can be used to build up a response. Otherwise it will be #f.

[procedure](handler-start [handler])

Starts the handler mainloop. handler is a thunk which is called for each incoming request with the above paramters set accordingly. It is expected to send a response to current-request. See send-response and send-http-response on how to do that.

[procedure](send-response body)

Sends the string body as the response for current-request.

[procedure](send-http-response #!key code reason body headers)

Sends a HTTP response for current-request. This procedure works exactly like spiffy's send-response.