HTTP - microfox-framework/MicroFox GitHub Wiki
๐ Routing Structure
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.
๐ฃ๏ธ Core Routing Concepts
-
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}
.
๐งฑ Routing Example
A minimal routing setup in MicroFox might look like this:
public class MainClass {
public static void main(String[] args) {
httpFilter("/book/add", ((request, response) -> {/*...*/}));
httpPost("/book/add", (req, resp) -> {/*...*/});
httpGet("/book/findAll", (request, response) -> {/*...*/});
httpDelete("/book/remove?id=12", (request, response) -> {/*...*/});
httpGet("/api/:name/:age", (request, response) -> {/*...*/});
}
}
๐งช Functional Design Advantages
- 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.
๐งฉ Integration with Other Layers
Routes in MicroFox typically delegate to stateless services or functional handlers, preserving the architecture's purity and separation of concerns.
router.get("/products", productService::handleList);