vibe.d beta banner
get vibe.d

Asynchronous I/O that doesn’t get in your way, written in D

Function registerRestInterface

Registers a REST interface and connects it the the given instance.

URLRouter registerRestInterface(TImpl) (
  URLRouter router,
  TImpl instance,
  RestInterfaceSettings settings = null

URLRouter registerRestInterface(TImpl) (
  URLRouter router,
  TImpl instance,
  MethodStyle style

URLRouter registerRestInterface(TImpl) (
  URLRouter router,
  TImpl instance,
  string url_prefix,
  MethodStyle style = MethodStyle.lowerUnderscored

Each method of the given class instance is mapped to the corresponing HTTP verb. Property methods are mapped to GET/PUT and all other methods are mapped according to their prefix verb. If the method has no known prefix, POST is used. The rest of the name is mapped to the path of the route according to the given method_style. Note that the prefix word must be all-lowercase and is delimited by either an upper case character, a non-alphabetic character, or the end of the string.

The following table lists the mappings from prefix verb to HTTP verb:

HTTP method Recognized prefixes
GET get, query
PUT set, put
POST add, create, post
DELETE remove, erase, delete
PATCH update, patch

If a method has its first parameter named 'id', it will be mapped to ':id/method' and 'id' is expected to be part of the URL instead of a JSON request. Parameters with default values will be optional in the corresponding JSON request.

Any interface that you return from a getter will be made available with the base url and its name appended.


router The HTTP router on which the interface will be registered
instance Class instance to use for the REST mapping - Note that TImpl must either be an interface type, or a class which derives from a single interface
settings Additional settings, such as the MethodStyle, or the prefix. See RestInterfaceSettings for more details.

See Also

RestInterfaceClient class for a seamless way to access such a generated API


This is a very limited example of REST interface features. Please refer to the "rest" project in the "examples" folder for a full overview.

All details related to HTTP are inferred from the interface declaration.


Sönke Ludwig, Михаил Страшун


© 2012-2016 RejectedSoftware e.K.


Subject to the terms of the MIT license, as written in the included LICENSE.txt file.