-
Notifications
You must be signed in to change notification settings - Fork 0
HTTP
In MicroFox, routing is designed to be lightweight, explicit, and function-oriented, avoiding the complexity of traditional annotation-based frameworks like Spring MVC or Jakarta REST.
Instead of relying on annotations such as @GetMapping or @Path, MicroFox defines routes programmatically, making the entire routing layer more transparent, predictable, and functional.
To enable http in your MicroFox application, simply add the following Maven dependency:
<dependency>
<groupId>ir.moke.microfox</groupId>
<artifactId>microfox-http</artifactId>
<version>${microfox.version}</version>
</dependency> -
Routes are first-class objects:
Each route is defined as a simple function or lambda that takes a request and produces a response. -
No reflection or annotation scanning:
This improves startup time and keeps routing explicit and debuggable. -
Routing table is declared centrally:
Developers define all routes in one place, making the application structure easier to understand and test. -
Pattern-based matching:
Route paths can include wildcards or parameterized segments, like/user/{id}.
A minimal routing setup in MicroFox might look like this:
public class MainClass {
public static void main(String[] args) {
httpRouter("/book/add" ,Method.POST ,(request, response) -> {/*...*/});
httpRouter("/book/findAll" ,Method.GET ,(request, response) -> {/*...*/});
httpRouter("/book/remove?id=12" ,Method.DELETE ,(request, response) -> {/*...*/});
httpRouter("/api/:name/:age" ,Method.GET ,(request, response) -> {/*...*/});
}
}- Testability: Each route is a pure function and can be tested in isolation.
- No hidden magic: No auto-wiring, no annotation scanning.
- Startup speed: Routing is defined statically and does not rely on classpath scanning.
- Memory efficiency: Minimal runtime metadata.
Routes in MicroFox typically delegate to stateless services or functional handlers, preserving the architecture's purity and separation of concerns.
MicroFox HTTP Server can be configured entirely via environment variables or .properties files. Below is a list of supported configuration keys:
| Key | Description | Example / Default |
|---|---|---|
| MICROFOX_HTTP_HOST | Host interface to bind the HTTP server | 0.0.0.0 |
| MICROFOX_HTTP_PORT | Port for HTTP traffic | 8080 |
| MICROFOX_HTTPS_PORT | Port for HTTPS traffic (if TLS is enabled) | 8443 |
| MICROFOX_HTTP_BASE_API | Base path for the HTTP API | / |
| MICROFOX_RESOURCE_BUNDLE_NAME | Java resource bundle for i18n validation messages | MicroFoxValidation |
| MICROFOX_KEYSTORE_PATH | Path to keystore file for HTTPS (optional) | (empty) |
| MICROFOX_KEYSTORE_PASSWORD | Password for the keystore | (empty) |
| MICROFOX_KEYSTORE_ALIAS_NAME | Alias name inside the keystore | (empty or custom) |
| MICROFOX_WORKER_THREAD_MIN | Min threads Jetty uses to process HTTP requests | 10 |
| MICROFOX_WORKER_THREAD_MAX | Max threads Jetty uses to process HTTP requests | 200 |
| MICROFOX_WORKER_THREAD_IDLE_TIMEOUT | Controls how long an idle worker thread (not processing any request) should be kept alive before being terminated | 30000 |
| MICROFOX_SOCKET_IDLE_TIMEOUT | Controls how long a socket connection can remain idle (no traffic) | 60000 |
| MICROFOX_SOCKET_ACCEPT_QUEUE_SIZE | Max pending TCP connections before Jetty accepts | 100 |
✅ If MICROFOX_KEYSTORE_PATH and related variables are configured, MicroFox will launch HTTPS on the specified MICROFOX_HTTPS_PORT.
To enable HTTPS, simply provide the keystore path, password, and alias. MicroFox will automatically configure the TLS context and bind both HTTP and HTTPS ports simultaneously if configured.
MICROFOX_KEYSTORE_PATH=/etc/ssl/microfox.jks
MICROFOX_KEYSTORE_PASSWORD=changeit
MICROFOX_KEYSTORE_ALIAS_NAME=microfox