serveRestJSClient

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

  1. HTTPServerRequestDelegate serveRestJSClient(RestInterfaceSettings settings)
    HTTPServerRequestDelegate
    serveRestJSClient
    (
    I
    )
    if (
    is(I == interface)
    )
  2. HTTPServerRequestDelegate serveRestJSClient(URL base_url)
  3. HTTPServerRequestDelegate serveRestJSClient(string base_url)
  4. HTTPServerRequestDelegate serveRestJSClient()

Examples

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');")
*/

Meta