RestInterfaceClient

Implements the given interface by forwarding all public methods to a REST server.

The server must talk the same protocol as registerRestInterface() generates. Be sure to set the matching method style for this. The RestInterfaceClient class will derive from the interface that is passed as a template argument. It can be used as a drop-in replacement of the real implementation of the API this way.

Non-success: If a request failed, timed out, or the server returned an non-success status code, an vibe.web.common.RestException will be thrown.

Constructors

this
this(RestInterfaceSettings settings)
this(string base_url, MethodStyle style)
this(URL base_url, MethodStyle style)

Creates a new REST client implementation of I.

Members

Aliases

RequestBodyFilter
alias RequestBodyFilter = void delegate(HTTPClientRequest req, scope InputStream body_contents) @(safe)
Undocumented in source.
RequestFilter
alias RequestFilter = void delegate(HTTPClientRequest req) @(safe)
Undocumented in source.

Functions

request
Json request(HTTPMethod verb, string name, InetHeaderMap hdrs, string query, string body_, InetHeaderMap reqReturnHdrs, InetHeaderMap optReturnHdrs)

Perform a request to the interface using the given parameters.

Properties

requestBodyFilter
RequestBodyFilter requestBodyFilter [@property setter]
RequestBodyFilter requestBodyFilter [@property getter]

Optional request filter with access to the request body.

requestFilter
RequestFilter requestFilter [@property getter]
RequestFilter requestFilter [@property setter]
void delegate(HTTPClientRequest req) requestFilter [@property setter]

An optional request filter that allows to modify each request before it is made.

Examples

interface IMyApi
{
	// GET /status
	string getStatus();

	// GET /greeting
	@property string greeting();
	// PUT /greeting
	@property void greeting(string text);

	// POST /new_user
	void addNewUser(string name);
	// GET /users
	@property string[] users();
	// GET /:id/name
	string getName(int id);

	Json getSomeCustomJson();
}

void test()
{
	auto api = new RestInterfaceClient!IMyApi("http://127.0.0.1/api/");

	logInfo("Status: %s", api.getStatus());
	api.greeting = "Hello, World!";
	logInfo("Greeting message: %s", api.greeting);
	api.addNewUser("Peter");
	api.addNewUser("Igor");
	logInfo("Users: %s", api.users);
	logInfo("First user name: %s", api.getName(0));
}

Meta