vibe.d beta banner
get vibe.d
0.8.0

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

Class RestInterfaceClient

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

class RestInterfaceClient(I) ;

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.

Constructors

NameDescription
thisCreates a new REST client implementation of I.

Fields

NameTypeDescription
m_intfRestInterface!I*
m_requestFilterRestInterfaceClient.RequestFilter
m_subInterfacesstaticMap!(RestInterfaceClient,Info.SubInterfaceTypes)

Properties

NameTypeDescription
requestFilter[get, set]RestInterfaceClient.RequestFilterAn optional request filter that allows to modify each request before it is made.

Methods

NameDescription
requestPerform a request to the interface using the given parameters.

Aliases

NameDescription
Info
RequestFilter

Example

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));
}
Authors

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

Copyright

© 2012-2016 RejectedSoftware e.K.

License

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