vibe.web.web

Implements a declarative framework for building web interfaces.

This module contains the sister funtionality to the vibe.web.rest module. While the REST interface generator is meant for stateless machine-to-machine communication, this module aims at implementing user facing web services. Apart from that, both systems use the same declarative approach.

See registerWebInterface for an overview of how the system works.

Types 5

Encapsulates settings used to customize the generated web interface.

Fields
string urlPrefix
bool ignoreTrailingSlash
Methods
WebInterfaceSettings dup() @property const @safe
structSessionVar(T, string name)

Maps a web interface member variable to a session field.

Setting a SessionVar variable will implicitly start a session, if none has been started yet. The content of the variable will be stored in the session store and is automatically serialized and deserialized.

Note that variables of type SessionVar must only be used from within handler functions of a class that was registered using

registerWebInterface. Also note that two different session

variables with the same name parameter will access the same underlying data.

Fields
T m_initValue
Methods
const(T) value() @propertyAccesses the current value of the session variable.
void value(T new_value) @propertyditto
void opAssign(T new_value)
Constructors
this(T init_val)Initializes a session var with a constant value.
private structErrorDisplayAttribute(alias DISPLAY_METHOD)
Fields
__traits(identifier, DISPLAY_METHOD) displayMethodName
Methods
ErrorParamType getError(Exception ex, string field)
Nested Templates
GetErrorParamType(size_t idx)
Fields
private structRequestContext
Fields
HTTPServerRequest req
HTTPServerResponse res
string language
string function(string, string) @safe tr
string function(string, string, int, string) @safe tr_plural

Functions 16

fnURLRouter registerWebInterface(C : Object, MethodStyle method_style = MethodStyle.lowerUnderscored)(URLRouter router, C instance, WebInterfaceSettings settings = null)Registers a HTTP/web interface based on a class instance.
fnvoid redirect(string url, int status = HTTPStatus.found) @safeRedirects to the given URL.
fnvoid redirect(URL url, int status = HTTPStatus.found) @safeditto
fnvoid header(string name, string value) @safeSets a response header.
fnvoid status(int statusCode) @safeSets the response status code.
fnstring language() @property @safeReturns the agreed upon language.
fnHTTPServerRequest request() @property @safeReturns the current request.
fnHTTPServerResponse response() @property @safeReturns the current response.
fnvoid terminateSession() @safeTerminates the currently active session (if any).
fnstring trWeb(string text, string context = null) @safeTranslates text based on the language of the current web request.
fnstring trWeb(string text, string plural_text, int count, string context = null) @safeditto
fn@property errorDisplay(alias DISPLAY_METHOD)()Attribute to customize how errors/exceptions are displayed.
fnNestedNameStyleAttribute nestedNameStyle(NestedNameStyle style)Determines how nested D fields/array entries are mapped to form field names. Note that this attribute only works if applied to the class.
private fnRequestContext getRequestContext() @trusted nothrow
private fnvoid handleRequest(string M, alias overload, C, ERROR...)(HTTPServerRequest req, HTTPServerResponse res, C instance, WebInterfaceSettings settings, ERROR error) if (ERROR.length <= 1)
private fnRequestContext createRequestContext(alias handler)(HTTPServerRequest req, HTTPServerResponse res)

Variables 1

varTaskLocal!RequestContext s_requestContext

Templates 1

tmplrender(string diet_file, ALIASES...)

Renders a Diet template file to the current HTTP response.

This function is equivalent to vibe.http.server.render, but implicitly writes the result to the response object of the currently processed request.

Note that this may only be called from a function/method registered using registerWebInterface.

In addition to the vanilla render function, this one also makes additional functionality available within the template:

  • The req variable that holds the current request object
  • If the @translationContext attribute us used, enables the

    built-in i18n support of Diet templates

Functions
void render(string MODULE = __MODULE__, string FUNCTION = __FUNCTION__)()