Added websockets.md and handler-default-implementation.md

This commit is contained in:
Relism
2025-02-27 00:59:41 +01:00
parent f07554408d
commit a5eac9e6a0
9 changed files with 233 additions and 143 deletions
+7 -11
View File
@@ -9,27 +9,23 @@ In this section, we discuss how to use the `FlashServer` router to manage our `R
The router is used to define route endpoints and their corresponding handler, which are executed when a request is made to the server.
The `FlashServer` router is an instance of the `RouteController` class, each server instance has its own router instance.
To access the router instance, you can call the `route()` method on either the internal server or your `FlashServer` instance.
To access the router instance, you can call the `route()` method on the `FlashServer` instance.
## Creating a Route
To create a route, you need to call the `route()` method on your server's instance (in this case for simplicity, on the InternalFlashServer)
and specify the base path of the route, followed by your handler class and optionally a `RouteInterceptor` instance.
and specify the base path of the route, followed by your handler class,
(More on the concept of `RouteInterceptor` in the following sections).
```java{8,9}
```java{9}
// Example.java
import static flash.InternalFlashServer.*;
public class Example {
public static void main(String[] args) {
port(8080);
FlashServer server = new FlashServer(8080);
route("/api")
server.route("/api")
.register(MyHandler.class);
start();
server.start();
}
}
```
@@ -40,7 +36,7 @@ import flash.Request;
import flash.Response;
import flash.models.RequestHandler;
@RouteInfo(method = HttpMethod.GET, path = "/hello", enforceNonNullBody = false)
@RouteInfo(method = HttpMethod.GET, path = "/hello")
public class MyHandler extends RequestHandler {
public MyHandler(Request req, Response res) {
super(req, res);