Function registerWebInterface
Registers a HTTP/web interface based on a class instance
.
Each public method corresponds to one or multiple request URLs.
Supported types...
...
Prototype
void registerWebInterface(C, vibe.web.common.MethodStyle method_style)( URLRouter router, C instance, WebInterfaceSettings settings );
Example
Gives an overview of the basic features. For more advanced use, see the example in the "examples/web/" directory.
import vibe.http.router; import vibe.http.server; import vibe.web.web; class WebService { private { SessionVar!(string, "login_user") m_loginUser; } @path("/") void getIndex(string _error = null) { //render!("index.dt", _error); } // automatically mapped to: POST /login @errorDisplay!getIndex void postLogin(string username, string password) { enforceHTTP(username.length > 0, HTTPStatus.forbidden, "User name must not be empty."); enforceHTTP(password == "secret", HTTPStatus.forbidden, "Invalid password."); m_loginUser = username; redirect("/profile"); } // automatically mapped to: POST /logout void postLogout() { terminateSession(); redirect("/"); } // automatically mapped to: GET /profile void getProfile() { enforceHTTP(m_loginUser.length > 0, HTTPStatus.forbidden, "Must be logged in to access the profile."); //render!("profile.dt") } } 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-2014 RejectedSoftware e.K.
License
Subject to the terms of the MIT license, as written in the included LICENSE.txt file.