vibe.d beta banner
get vibe.d
0.10.1

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

Function redirect

Redirects to the given URL.

void redirect (
  string url,
  int status = 302
) @safe;

void redirect (
  URL url,
  int status = 302
) @safe;

The URL may either be a full URL, including the protocol and server portion, or it may be the local part of the URI (the path and an optional query string). Finally, it may also be a relative path that is combined with the path of the current request to yield an absolute path.

Note that this may only be called from a function/method registered using registerWebInterface.

Example

import vibe.data.json : Json;

class WebService {
	// POST /item
	void postItem() {
		redirect("/item/1");
	}
}

void run()
{
	auto router = new URLRouter;
	router.registerWebInterface(new WebService);

	auto settings = new HTTPServerSettings;
	settings.port = 8080;
	listenHTTP(settings, router);
}
Authors

Sönke Ludwig

Copyright

© 2013-2016 Sönke Ludwig

License

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