vibe.d beta banner
get vibe.d
0.10.1

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

Function serveRestJSClient

Returns a HTTP handler delegate that serves a JavaScript REST client.

HTTPServerRequestDelegate serveRestJSClient(I) (
  RestInterfaceSettings settings
)
if (is(I == interface));

HTTPServerRequestDelegate serveRestJSClient(I) (
  URL base_url
);

HTTPServerRequestDelegate serveRestJSClient(I) (
  string base_url
);

HTTPServerRequestDelegate serveRestJSClient(I)();

Example

import vibe.http.server;

interface MyAPI {
	string getFoo();
	void postBar(string param);
}

void test()
{
	auto restsettings = new RestInterfaceSettings;
	restsettings.baseURL = URL("http://api.example.org/");

	auto router = new URLRouter;
	router.get("/myapi.js", serveRestJSClient!MyAPI(restsettings));
	//router.get("/myapi.js", serveRestJSClient!MyAPI(URL("http://api.example.org/")));
	//router.get("/myapi.js", serveRestJSClient!MyAPI("http://api.example.org/"));
	//router.get("/myapi.js", serveRestJSClient!MyAPI()); // if want to request to self server
	//router.get("/", staticTemplate!"index.dt");

	listenHTTP(new HTTPServerSettings, router);
}

/*
	index.dt:
	html
		head
			title JS REST client test
			script(src="myapi.js")
		body
			button(onclick="MyAPI.postBar('hello');")
*/
Authors

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

Copyright

© 2012-2018 RejectedSoftware e.K.

License

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