public class RequestServer extends NanoHTTPD
Request routing is done by searching a list of registered handlers, in order of registration, for a handler whose path regex matches the request URI and whose HTTP method (GET, POST, DELETE...) matches the request's method. If none is found an HTTP 404 is returned.
A Handler class is parameterized by the kind of Schema that it accepts for request handling, as well as the internal implementation class (Iced class) that the Schema translates from and to. Handler methods are allowed to return other Schema types than in the type parameter if that makes sense for a given request. For example, a prediction (scoring) call on a Model might return a Frame schema.
When an HTTP request is accepted the framework does the following steps:
NanoHTTPD.Response
Modifier and Type | Field and Description |
---|---|
static int |
H2O_REST_API_VERSION |
static RequestServer |
SERVER |
HTTP_BADREQUEST, HTTP_FORBIDDEN, HTTP_INTERNALERROR, HTTP_NOTFOUND, HTTP_NOTIMPLEMENTED, HTTP_NOTMODIFIED, HTTP_OK, HTTP_PARTIALCONTENT, HTTP_RANGE_NOT_SATISFIABLE, HTTP_REDIRECT, HTTP_TOOLONGREQUEST, HTTP_UNAUTHORIZED, MIME_DEFAULT_BINARY, MIME_HTML, MIME_JSON, MIME_PLAINTEXT, MIME_XML, myOut
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
addToNavbar(water.api.Route route,
java.lang.String base_url,
java.lang.String name,
java.lang.String category) |
static void |
alwaysLogRequest(java.lang.String uri,
java.lang.String method,
java.util.Properties parms) |
protected static water.api.Route |
lookup(java.lang.String http_method,
java.lang.String uri) |
static int |
numRoutes() |
static water.api.Route |
register(java.lang.String uri_pattern,
java.lang.String http_method,
java.lang.Class<? extends Handler> handler_class,
java.lang.String handler_method,
java.lang.String summary)
Deprecated.
|
static water.api.Route |
register(java.lang.String uri_pattern,
java.lang.String http_method,
java.lang.Class<? extends Handler> handler_class,
java.lang.String handler_method,
java.lang.String[] path_params,
java.lang.String summary)
Deprecated.
|
static water.api.Route |
register(java.lang.String uri_pattern,
java.lang.String http_method,
java.lang.Class<? extends Handler> handler_class,
java.lang.String handler_method,
java.lang.String doc_method,
java.lang.String summary)
Register an HTTP request handler for a given URI pattern, with no path parameters.
|
static water.api.Route |
register(java.lang.String uri_pattern_raw,
java.lang.String http_method,
java.lang.Class<? extends Handler> handler_class,
java.lang.String handler_method,
java.lang.String doc_method,
java.lang.String[] path_params,
java.lang.String summary)
Register an HTTP request handler method for a given URL pattern, with parameters extracted from the URI.
|
static water.api.Route |
register(java.lang.String uri_pattern_raw,
java.lang.String http_method,
java.lang.Class<? extends Handler> handler_class,
java.lang.String handler_method,
java.lang.String doc_method,
java.lang.String[] path_params,
java.lang.String summary,
HandlerFactory handler_factory)
Register an HTTP request handler method for a given URL pattern, with parameters extracted from the URI.
|
static java.util.Collection<water.api.Route> |
routes() |
NanoHTTPD.Response |
serve(java.lang.String uri,
java.lang.String method,
java.util.Properties header,
java.util.Properties parms)
Override this to customize the server.
|
static java.lang.Runnable |
start() |
public static final int H2O_REST_API_VERSION
public static RequestServer SERVER
public static final int numRoutes()
public static final java.util.Collection<water.api.Route> routes()
@Deprecated public static water.api.Route register(java.lang.String uri_pattern, java.lang.String http_method, java.lang.Class<? extends Handler> handler_class, java.lang.String handler_method, java.lang.String summary)
@Deprecated public static water.api.Route register(java.lang.String uri_pattern, java.lang.String http_method, java.lang.Class<? extends Handler> handler_class, java.lang.String handler_method, java.lang.String[] path_params, java.lang.String summary)
public static water.api.Route register(java.lang.String uri_pattern, java.lang.String http_method, java.lang.Class<? extends Handler> handler_class, java.lang.String handler_method, java.lang.String doc_method, java.lang.String summary)
URIs which match this pattern will have their parameters collected from the query params.
uri_pattern
- regular expression which matches the URL path for this request handler; parameters that are embedded in the path must be captured with <code>(?<parm>.*)</code> syntaxhttp_method
- HTTP verb (GET, POST, DELETE) this handler will accepthandler_class
- class which contains the handler methodhandler_method
- name of the handler methoddoc_method
- name of a method which returns GitHub Flavored Markdown documentation for the requestRoute
,
RequestServer
public static water.api.Route register(java.lang.String uri_pattern_raw, java.lang.String http_method, java.lang.Class<? extends Handler> handler_class, java.lang.String handler_method, java.lang.String doc_method, java.lang.String[] path_params, java.lang.String summary)
URIs which match this pattern will have their parameters collected from the path and from the query params
uri_pattern_raw
- regular expression which matches the URL path for this request handler; parameters that are embedded in the path must be captured with <code>(?<parm>.*)</code> syntaxhttp_method
- HTTP verb (GET, POST, DELETE) this handler will accepthandler_class
- class which contains the handler methodhandler_method
- name of the handler methoddoc_method
- name of a method which returns GitHub Flavored Markdown documentation for the requestpath_params
- list of parameter names to extract from the uri_pattern; they are matched by name from the named pattern capture groupsummary
- short help string which summarizes the functionality of this endpointRoute
,
RequestServer
public static water.api.Route register(java.lang.String uri_pattern_raw, java.lang.String http_method, java.lang.Class<? extends Handler> handler_class, java.lang.String handler_method, java.lang.String doc_method, java.lang.String[] path_params, java.lang.String summary, HandlerFactory handler_factory)
URIs which match this pattern will have their parameters collected from the path and from the query params
uri_pattern_raw
- regular expression which matches the URL path for this request handler; parameters that are embedded in the path must be captured with <code>(?<parm>.*)</code> syntaxhttp_method
- HTTP verb (GET, POST, DELETE) this handler will accepthandler_class
- class which contains the handler methodhandler_method
- name of the handler methoddoc_method
- name of a method which returns GitHub Flavored Markdown documentation for the requestpath_params
- list of parameter names to extract from the uri_pattern; they are matched by name from the named pattern capture groupsummary
- short help string which summarizes the functionality of this endpointhandler_factory
- factory to create instance of handlerRoute
,
RequestServer
protected static water.api.Route lookup(java.lang.String http_method, java.lang.String uri)
public static java.lang.Runnable start()
public static void alwaysLogRequest(java.lang.String uri, java.lang.String method, java.util.Properties parms)
public NanoHTTPD.Response serve(java.lang.String uri, java.lang.String method, java.util.Properties header, java.util.Properties parms)
NanoHTTPD
(By default, this delegates to serveFile() and allows directory listing.)
serve
in class NanoHTTPD
uri
- Percent-decoded URI without parameters, for example "/index.cgi"method
- "GET", "POST" etc.header
- Header entries, percent decodedparms
- Parsed, percent decoded parameters from URI and, in case of POST, data.public static java.lang.String addToNavbar(water.api.Route route, java.lang.String base_url, java.lang.String name, java.lang.String category)