Zero-dependencies HTTP Framework based on ExpressJS
public class Example {
public static void main(String[] args) {
new Murmux()
.rootHandler(xc -> xc.commitText("Hello world"))
.listen(8080); // Will listen on port 8080
}
}
Available in Maven Central.
implementation("io.vacco.murmux:murmux:<LATEST_VERSION>")
You can add routes (And middlewares) directly to handle requests. Direct also supports methods like POST
PATCH
DELETE
and PUT
, others need to be created manually:
However, it's better to split your code. You can create routes and add them at runtime:
You can create handlers for all request-methods and contexts. Some examples:
Sometimes you want to create dynamic URLs where some parts are not static. With the {}
operator you can create variables in the URL which will be saved later in a HashMap
.
Example request: GET /posts/john/all
:
If you make a request which contains queries, you can access the queries over req.getQuery(NAME)
.
Example request: GET /posts?page=12&from=john
:
With req.cookies.get(NAME)
you can get a cookie by his name, and with res.withCookie(NAME, VALUE)
you can easily set a cookie.
Example request: GET /setcookie
and GET /showcookie
:
Use req.getFormParam(NAME)
to receive values from input elements of an HTML-Form.
Warning: Currently, File-inputs don't work, if there is a File-input the data won't get parsed!
Middleware allows you to handle a request before it reaches any other request handler.
Middlewares work exactly as request handlers.
You can also filter by request-methods and contexts:
Core middlewares are included in MxMiddleware.
To realize a CORS api you can use the CORS middleware.
Use MxStatic to serve static content.
Example:
A simple in-memory cookie-session middleware is provided:
Requires Gradle 7.1 or later.
Create a file with the following content at ~/.gsOrgConfig.json
:
{
"orgId": "vacco-oss",
"orgConfigUrl": "https://vacco-oss.s3.us-east-2.amazonaws.com/vacco-oss.json"
}
Then run:
gradle clean build