Class RestInterfaceClient!(I)

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.

Inherits from

Fields

Field name Field Type Descrption
m_baseUrl Url
m_methodStyle MethodStyle
m_requestFilter RestInterfaceClient.RequestFilter

Methods

Method name Description
this Creates a new REST implementation of I
requestFilter An optional request filter that allows to modify each request before it is made.
request

Aliases

Alias name Description
RequestFilter
BaseInterface

Examples

An example client that accesses the API defined in the registerRestInterface() example:

import vibe.d;

interface IMyApi {
	string getStatus();

	@property string greeting();
	@property void greeting(string text);

	void addNewUser(string name);
	@property string[] users();
	string[] index();
	string getName(int id);
}

static this()
{
	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);
}

Authors

Sönke Ludwig

Copyright

© 2012 RejectedSoftware e.K.

License

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