Javalin, A simple web framework for Java and Kotlin.
TOC
import io.javalin.Javalin;
public class HelloWorld {
public static void main(String[] args) {
Javalin app = Javalin.create().start(7000);
app.get("/", ctx -> ctx.result("Hello World"));
}
}
Context
ctx.appAttribute(class) // get an attribute set on the app
ctx.register(class, object) // register an extension on the context
ctx.use(class) // use an extension on the context
ctx.cookieStore(key) // get cookie store value
ctx.cookieStore(key, value) // set a cookie store value
ctx.clearCookieStore() // clear the cookie store
ctx.matchedPath() // path that was used to match request (also includes before/after paths)
ctx.endpointHandlerPath() // endpoint path that was used to match request (null in before, available in after)
// Request methods
ctx.body() // get body as string (consumes underlying request body if not cached)
ctx.bodyAsBytes() // get body as bytes (consumes underlying request body if not cached)
ctx.bodyAsClass(class) // get body as class (consumes underlying request body if not cached)
ctx.bodyValidator(class) // get typed validator for body (consumes underlying body request if not cached)
ctx.uploadedFile(name) // get uploaded file by name
ctx.uploadedFiles(name) // get uploaded file(s) by name
ctx.formParam(key) // get form parameter
ctx.formParam(key, default) // get form parameter (or default value)
ctx.formParam(key, class) // get form parameter as class
ctx.formParam(key, class, default) // get form parameter (or default value) as class
ctx.formParams(key) // get form parameters (multiple)
ctx.formParamMap() // get form parameter map
ctx.pathParam(key) // get path parameter
ctx.pathParam(key, class) // get path as class
ctx.pathParamMap() // get path parameter map
ctx.basicAuthCredentials() // get basic auth credentials (username/pwd)
ctx.basicAuthCredentialsExist() // check if proper basic auth credentials exist
ctx.attribute(key, value) // set request attribute
ctx.attribute(key) // get request attribute
ctx.attributeMap() // get request attribute map
ctx.contentLength() // get request content length
ctx.contentType() // get request content type
ctx.cookie(name) // get request cookie
ctx.cookieMap() // get request cookie map
ctx.header(header) // get request header
ctx.headerMap() // get request header map
ctx.host() // get request host
ctx.ip() // get request host
ctx.isMultipart() // check if request is multipart
ctx.isMultipartFormData() // check if request is multipart/form data
ctx.method() // get request method
ctx.path() // get request path
ctx.port() // get request port
ctx.protocol() // get request protocol
ctx.queryParam(key) // get query parameter
ctx.queryParam(key, default) // get query parameter (or default value)
ctx.queryParam(key, class) // get query parameter as class
ctx.queryParam(key, class, default) // get query parameter (or default value) as class
ctx.queryParams(key) // get query parameters (multiple)
ctx.queryParamMap() // get query parameter map
ctx.queryString() // get query string
ctx.scheme() // get request scheme
ctx.sessionAttribute(key, value) // set session attribute (server side attribute)
ctx.sessionAttribute(key) // get session attribute
ctx.sessionAttributeMap() // get attribute map
ctx.url() // get request url
ctx.fullUrl() // get request url + query param
ctx.contextPath() // get request context path
ctx.userAgent() // get request user agent
// Response methods
ctx.result(resultString) // set a string result that will be sent to the client
ctx.resultString() // get the string result that will be sent to the client
ctx.result(resultStream) // set a stream result that will be sent to the client
ctx.result(byteArray) // set a byte[] result that will be sent to the client
ctx.resultStream() // get the stream that will be sent to the client
ctx.result(future) // set a future result that will be sent to the client (async)
ctx.resultFuture() // get the future result that will be sent to the client
ctx.seekableStream(resultStream) // set a stream that will be sent to the client in byte ranges
ctx.contentType(contentType) // set the response content type
ctx.header(name, value) // set a response header
ctx.redirect(location) // send a redirect response to location
ctx.redirect(location, httpStatusCode) // send a redirect response to location with status code
ctx.status(statusCode) // set response status
ctx.status() // get response status
ctx.cookie(name, value) // set cookie by name and value
ctx.cookie(cookie) // set cookie
ctx.removeCookie(name, path) // remove a cookie
ctx.html(html) // call result(string).contentType("text/html")
ctx.json(obj) // call result(JavalinJson.toJson(obj)).contentType("application/json")
ctx.json(future) // call result(future(JavalinJson.toJson(future))).contentType("application/json")
ctx.render(filePath, model) // call html(JavalinRenderer.render(filePath, model)