vibe.web.common

Contains common functionality for the REST and WEB interface generators.

Types 15

classRestException : HTTPStatusException

Respresents a Rest error response

Fields
Json m_jsonResult
Methods
inout(Json) jsonResult() @property inout nothrow pure @safe @nogcThe result text reported to the client
Constructors
this(int status, string result, string file = __FILE__, int line = __LINE__, Throwable next = null)
this(int status, Json jsonResult, string file = __FILE__, int line = __LINE__, Throwable next = null)

private

Fields
string data

private

Fields
HTTPMethod data
aliasresultSerializer(alias serialize, alias deserialize, string content_type) = ResultSerializer!(serialize, deserialize, content_type)

UDA for using a custom serializer for the method return value.

Instead of using the default serializer (JSON), this allows to define custom serializers. Multiple serializers can be specified and will be matched against the Accept header of the HTTP request.

Parameters

serializeAn alias to a generic function taking an output range as its first argument and the value to be serialized as its second argument. The result of the serialization is written byte-wise into the output range.
deserializeAn alias to a generic function taking a forward range as its first argument and a reference to the value that is to be deserialized.
content_typeThe MIME type of the serialized representation.
structResultSerializer(alias ST, alias DT, string ContentType)

private

Fields
ContentType contentType
aliasDefaultSerializerT = ResultSerializer!( defaultSerialize, defaultDeserialize, "application/json; charset=UTF-8")
structSerPolicy(alias PolicyTemplatePar)
aliasserializationPolicy(Args...) = SerPolicy!(Args)

This struct contains the name of a route specified by the path function.

Fields
string dataThe specified path

private

This struct contains a mapping between the name used by HTTP (field) and the parameter (identifier) name of the function.

Fields
ParameterKind originThe type of the WebParamAttribute
string identifierParameter name (function parameter name).
string fieldThe meaning of this field depends on the origin. (HTTP request name)

Determines the naming convention of an identifier.

unalteredSpecial value for free-style conventions
camelCasecamelCaseNaming
pascalCasePascalCaseNaming
lowerCaselowercasenaming
upperCaseUPPERCASENAMING
lowerUnderscoredlowercasenaming
upperUnderscoredUPPERCASENAMING
lowerDashedlower-case-naming
upperDashedUPPER-CASE-NAMING

Speficies how D fields are mapped to form field names

underscoreUse underscores to separate fields and array indices
dUse native D style and separate fields by dots and put array indices into brackets
Fields
string field
string text
ok
skipped
error

Functions 23

fnstring adjustMethodStyle(string name, MethodStyle style) @safeAdjusts the naming convention for a given function name to the specified style.
fnauto extractHTTPMethodAndName(alias Func, bool indexSpecialCase)()Determines the HTTP method and path for a given function symbol.
fnContentTypeAttribute contentType(string data) @safeAttribute to define the content type for methods.
fnMethodAttribute method(HTTPMethod data) @safeAttribute to force a specific HTTP method for an interface method.
fnPathAttribute path(string data) @safeAttibute to force a specific URL path.
fnPathAttribute rootPathFromName() @property @safeConvenience alias to generate a name from the interface's name.
fnNoRouteAttribute noRoute() @propertyMethods marked with this attribute will not be treated as web endpoints.
fnvoid defaultSerialize(alias P, T, RT)(ref RT output_range, const scope ref T value)
fnT defaultDeserialize(alias P, T, R)(R input_range)
fnWebParamAttribute viaBody(string field = null) @safeDeclare that a parameter will be transmitted to the API through the body.
fnWebParamAttribute bodyParam(string identifier, string field) @safeDitto
fnWebParamAttribute bodyParam(string identifier) @safeditto
fnWebParamAttribute viaHeader(string field) @safeDeclare that a parameter will be transmitted to the API through the headers.
fnWebParamAttribute headerParam(string identifier, string field) @safeDitto
fnWebParamAttribute viaQuery(string field) @safeDeclare that a parameter will be transmitted to the API through the query string.
fnWebParamAttribute queryParam(string identifier, string field) @safeDitto
fnstring concatURL(string prefix, string url, bool trailing = false) @safe
private fnParamResult processFormParam(T)(scope string data, string fieldname, ref T dst, ref ParamError err)
fnParamResult readFormParamRec(T)(scope HTTPServerRequest req, ref T dst, string fieldname, bool required, NestedNameStyle style, ref ParamError err)
fnbool webConvTo(T)(string str, ref T dst, ref ParamError err) nothrow
fnvoid setVoid(T, U)(ref T dst, U value)
private fnstring getArrayFieldName(T)(NestedNameStyle style, string prefix, T index)
private fnstring getMemberFieldName(NestedNameStyle style, string prefix, string member) @safe

Variables 2

enumvarviaStatus = WebParamAttribute(ParameterKind.status)

Declares a parameter to be transmitted via the HTTP status code or phrase.

This attribute can be applied to one or two out parameters of type HTTPStatus/int or string. The values of those parameters correspond to the HTTP status code or phrase, depending on the type.

private enumvarMAX_ARR_INDEX = 0xffff

Templates 3

tmplResultSerializersT(alias func)

Convenience template to get all the ResultSerializers for a function

tmplSerPolicyT(Iface)
tmplisNullable(T)

private