Service handlers

Output modules

Once the service identification mechanism identifies the service responsible for a given URL, it executes its service handler. The service handler is a function taking the GET and POST parameters as arguments and returning the content to be sent to the client. The return type of the service handler depends on the function used to register it. The most common case is HTML content build with the TyXML library, but Eliom additionally provides a lot of output modules to ease the implementation of common Web interaction. See section Predefined output modules for a comprehensive list.

List of predefined output modules

Services can send several types of data, using a variety of predefined modules. It is also possible to create your own output modules. The main predefined output modules are:

Generating content for the browser

Eliom_registration.​Html
Registration of functions that generate HTML pages statically checked using polymorphic variant types. You may use constructor functions from Eliom_content.​Html.​D or a syntax extension close to the standard HTML syntax.
Eliom_registration.​Flow5
Registration of functions that generate a portion of page using Eliom_content.​Html.​F or the syntax extension (useful for XMLHttpRequest requests for example). Do not use with Eliom applications: you can instead use Error a_api: invalid contents to call server functions that produce HTML nodes.
Eliom_registration.​HtmlText
Registration of functions that generate text HTML pages, without any validation of the content. The content type sent by the server is "text/html".
Eliom_registration.​CssText
Registration of functions that generate CSS pages, without any validation of the content. The content type sent by the server is "text/css".
Eliom_registration.​String
Registration of functions that generate text pages, without any validation of the content. The services return a pair of strings. The first string is the content of the page, while the second string is the content type.
Eliom_registration.​File
Registration of services that send files. See here for an example of use.
Eliom_registration.​Streamlist
Registration of services that send "byte" contents. It is used when big content (that does not fit in memory) is generated.

Generating content for client-server applications

Eliom_registration.​App
Functor that allows creation of services belonging to a client-server Eliom application (see chapter client-server applications).

Special browser interraction

Eliom_registration.​Action
Registration of actions (functions that do not generate any page. See Action). The page corresponding to the URL (without the special parameter identifying the action) is reloaded after the action by default if possible.
Eliom_registration.​Unit
Like Eliom_registration.​Action, but the URL is not reloaded after the action. (Same as Eliom_registration.Action with [`NoReload] option).
Eliom_registration.​Redirection
Registration of HTTP redirections. The handler returns the service (without parameter) of the page you want to redirect to. The browser will get a 301 or 307 code in answer and redo the request to the new URL. To specify whether you want temporary (307) or permanent (301) redirections, use the ?options parameter of registration functions. For example: register options:`Permanent ... or register options:`Temporary ....
Eliom_registration.​String_redirection
Same but the ouput type is a string. Use with care! Warning: According to the RFC of the HTTP protocol, the URL must be absolute!

Customization of other outputs

Eliom_registration.​Customize
Specialization of service registration functions by customizing the page type.

Sending caml values to client side code

Eliom_registration.​Ocaml
Registration of services sending marshalled OCaml values. See the section on communications in the chapter about client-server applications.

Runtime choice of content

Eliom_registration.​Any
Registration of services that can choose what they send, for example an HTML page or a file, depending on some situation (parameter, user logged or not, page present in a cache ...). It is also possible to create your own modules for other types of pages. See here for an example of use.

Advanced output modules

Sending files

You may want to register a service that sends files. To do so, use the Eliom_registration.​File module. Example:

let sendfile =
  Eliom_registration.File.create
    ~path:(Eliom_service.Path ["sendfile"])
    ~meth:(Eliom_service.Get Eliom_parameter.unit)
    (fun () () ->