diff --git a/404.html b/404.html index 5dadf5c..47f6ec2 100644 --- a/404.html +++ b/404.html @@ -17,7 +17,7 @@
- + \ No newline at end of file diff --git a/assets/flash_core-concepts_handlers.md.BZuBmBSX.js b/assets/flash_core-concepts_handlers.md.BZuBmBSX.js new file mode 100644 index 0000000..d0e6bcf --- /dev/null +++ b/assets/flash_core-concepts_handlers.md.BZuBmBSX.js @@ -0,0 +1,3 @@ +import{_ as t,c as a,a0 as s,o as n}from"./chunks/framework.p2VkXzrt.js";const u=JSON.parse('{"title":"📚 Handlers","description":"","frontmatter":{"banner-title":"Flash - Handlers","banner-description":"Learn about handlers in Flash and the different types available.","head":[["meta",{"name":"twitter:image","content":"/assets/banner-cards/flash-core-concepts-handlers.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/flash-core-concepts-handlers.png"}],["meta",{"name":"twitter:card","content":"summary_large_image"}],["meta",{"name":"twitter:image:height","content":"1280"}],["meta",{"name":"twitter:image:width","content":"669"}],["meta",{"name":"twitter:description","content":""}]]},"headers":[],"relativePath":"flash/core-concepts/handlers.md","filePath":"flash/core-concepts/handlers.md"}'),i={name:"flash/core-concepts/handlers.md"};function r(o,e,l,d,h,c){return n(),a("div",null,e[0]||(e[0]=[s(`

📚 Handlers

In Flash, handlers are the building blocks of your application logic. They are responsible for processing incoming requests, executing the necessary logic, and generating the appropriate response.

There are several types of handlers in Flash, each serving a specific purpose and providing a different level of control over the request lifecycle. Understanding the different handler types will help you structure your application logic more effectively and make the most out of Flash's powerful routing system.

📦 Routing Behavior

Before diving into the different handler types, it's essential to understand how routing works in Flash. When a request is received by the server, Flash matches the request path and method against the registered routes to find the appropriate handler. The handler is then executed, and its response is sent back to the client.

Flash supports 3 main types of routing behaviors:

📌 Handler Types

1. RequestHandler

The RequestHandler is the "standard" type of handler in Flash, it provides the most control over the request lifecycle and allows you to define custom logic for handling requests. You can extend the RequestHandler class to create custom handlers that process incoming requests and generate responses.

Because RequestHandler is an abstract class, you need to implement both the handle() method and the super constructor in your custom handler to define the logic that should be executed when a request is received.

Since RequestHandler is an abstract class, you can leverage and chain HDI's to create cleaner and more maintainable route logic (more on that in the Handler Default Implementations guide).

2. SimpleHandler

The SimpleHandler is a lightweight handler that allows you to define request handling logic in a single method using lambda notation. It is useful for simple request processing tasks that don't require the full lifecycle control provided by RequestHandler.

To create a SimpleHandler, you can use the server.get(), server.post(), server.put(), server.delete() etc. in general, you can use the server.<METHOD>() methods to register the handler with the server.

The arguments for these methods are the route path and a lambda expression that provides the request and response objects and defines the request handling logic.

java
server.get("/hello", (req, res) -> {
+    return "Hello, World!";
+});

Both RequestHandler and SimpleHandler can specify the router behavior by the naming convention of the endpoint used to register the handler.

`,20)]))}const g=t(i,[["render",r]]);export{u as __pageData,g as default}; diff --git a/assets/flash_core-concepts_handlers.md.BZuBmBSX.lean.js b/assets/flash_core-concepts_handlers.md.BZuBmBSX.lean.js new file mode 100644 index 0000000..d0e6bcf --- /dev/null +++ b/assets/flash_core-concepts_handlers.md.BZuBmBSX.lean.js @@ -0,0 +1,3 @@ +import{_ as t,c as a,a0 as s,o as n}from"./chunks/framework.p2VkXzrt.js";const u=JSON.parse('{"title":"📚 Handlers","description":"","frontmatter":{"banner-title":"Flash - Handlers","banner-description":"Learn about handlers in Flash and the different types available.","head":[["meta",{"name":"twitter:image","content":"/assets/banner-cards/flash-core-concepts-handlers.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/flash-core-concepts-handlers.png"}],["meta",{"name":"twitter:card","content":"summary_large_image"}],["meta",{"name":"twitter:image:height","content":"1280"}],["meta",{"name":"twitter:image:width","content":"669"}],["meta",{"name":"twitter:description","content":""}]]},"headers":[],"relativePath":"flash/core-concepts/handlers.md","filePath":"flash/core-concepts/handlers.md"}'),i={name:"flash/core-concepts/handlers.md"};function r(o,e,l,d,h,c){return n(),a("div",null,e[0]||(e[0]=[s(`

📚 Handlers

In Flash, handlers are the building blocks of your application logic. They are responsible for processing incoming requests, executing the necessary logic, and generating the appropriate response.

There are several types of handlers in Flash, each serving a specific purpose and providing a different level of control over the request lifecycle. Understanding the different handler types will help you structure your application logic more effectively and make the most out of Flash's powerful routing system.

📦 Routing Behavior

Before diving into the different handler types, it's essential to understand how routing works in Flash. When a request is received by the server, Flash matches the request path and method against the registered routes to find the appropriate handler. The handler is then executed, and its response is sent back to the client.

Flash supports 3 main types of routing behaviors:

📌 Handler Types

1. RequestHandler

The RequestHandler is the "standard" type of handler in Flash, it provides the most control over the request lifecycle and allows you to define custom logic for handling requests. You can extend the RequestHandler class to create custom handlers that process incoming requests and generate responses.

Because RequestHandler is an abstract class, you need to implement both the handle() method and the super constructor in your custom handler to define the logic that should be executed when a request is received.

Since RequestHandler is an abstract class, you can leverage and chain HDI's to create cleaner and more maintainable route logic (more on that in the Handler Default Implementations guide).

2. SimpleHandler

The SimpleHandler is a lightweight handler that allows you to define request handling logic in a single method using lambda notation. It is useful for simple request processing tasks that don't require the full lifecycle control provided by RequestHandler.

To create a SimpleHandler, you can use the server.get(), server.post(), server.put(), server.delete() etc. in general, you can use the server.<METHOD>() methods to register the handler with the server.

The arguments for these methods are the route path and a lambda expression that provides the request and response objects and defines the request handling logic.

java
server.get("/hello", (req, res) -> {
+    return "Hello, World!";
+});

Both RequestHandler and SimpleHandler can specify the router behavior by the naming convention of the endpoint used to register the handler.

`,20)]))}const g=t(i,[["render",r]]);export{u as __pageData,g as default}; diff --git a/assets/flash_core-concepts_server-router.md.DIWo49Yl.js b/assets/flash_core-concepts_server-router.md.DIWo49Yl.js new file mode 100644 index 0000000..9184ad6 --- /dev/null +++ b/assets/flash_core-concepts_server-router.md.DIWo49Yl.js @@ -0,0 +1,24 @@ +import{_ as i,c as a,a0 as e,o as n}from"./chunks/framework.p2VkXzrt.js";const c=JSON.parse('{"title":"🛣️ Server Router","description":"","frontmatter":{"banner_title":"Flash - Server Router","banner_description":"Learn how to use the FlashServer router to create and manage RouteHandlers.","head":[["meta",{"name":"twitter:image","content":"/assets/banner-cards/flash-core-concepts-server-router.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/flash-core-concepts-server-router.png"}],["meta",{"name":"twitter:card","content":"summary_large_image"}],["meta",{"name":"twitter:image:height","content":"1280"}],["meta",{"name":"twitter:image:width","content":"669"}],["meta",{"name":"twitter:description","content":""}]]},"headers":[],"relativePath":"flash/core-concepts/server-router.md","filePath":"flash/core-concepts/server-router.md"}'),t={name:"flash/core-concepts/server-router.md"};function h(l,s,r,p,k,o){return n(),a("div",null,s[0]||(s[0]=[e(`

🛣️ Server Router

In this section, we discuss how to use the FlashServer router to manage our RequestHandler instances. 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 the FlashServer instance.

Creating a Route

To create a route, you need to call the route() method on your server's instance and specify the base path of the route, followed by your handler class,

java
// Example.java
+public class Example {
+    public static void main(String[] args) {
+        FlashServer server = new FlashServer(8080);
+        
+        server.route("/api")
+            .register(MyHandler.class);
+            
+        server.start();
+    }
+}
java
// MyHandler.java
+
+@RouteInfo(endpoint = "/hello", method = HttpMethod.GET)
+public class MyHandler extends RequestHandler {
+    public MyHandler(Request req, Response res) {
+        super(req, res);
+    }
+
+    @Override
+    public Object handle() {
+        String response = "Hello, world!";
+        return response;
+    }
+}

In the example above, we create an /api router and register the MyHandler class to handle requests on the /api/hello endpoint.

This is because the path property of the RouteInfo annotation is relative to the base path of the router, which in this case is /api.

Visiting /api/hello from your browser will result in the response Hello, world!.

`,10)]))}const E=i(t,[["render",h]]);export{c as __pageData,E as default}; diff --git a/assets/flash_core-concepts_server-router.md.DIWo49Yl.lean.js b/assets/flash_core-concepts_server-router.md.DIWo49Yl.lean.js new file mode 100644 index 0000000..9184ad6 --- /dev/null +++ b/assets/flash_core-concepts_server-router.md.DIWo49Yl.lean.js @@ -0,0 +1,24 @@ +import{_ as i,c as a,a0 as e,o as n}from"./chunks/framework.p2VkXzrt.js";const c=JSON.parse('{"title":"🛣️ Server Router","description":"","frontmatter":{"banner_title":"Flash - Server Router","banner_description":"Learn how to use the FlashServer router to create and manage RouteHandlers.","head":[["meta",{"name":"twitter:image","content":"/assets/banner-cards/flash-core-concepts-server-router.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/flash-core-concepts-server-router.png"}],["meta",{"name":"twitter:card","content":"summary_large_image"}],["meta",{"name":"twitter:image:height","content":"1280"}],["meta",{"name":"twitter:image:width","content":"669"}],["meta",{"name":"twitter:description","content":""}]]},"headers":[],"relativePath":"flash/core-concepts/server-router.md","filePath":"flash/core-concepts/server-router.md"}'),t={name:"flash/core-concepts/server-router.md"};function h(l,s,r,p,k,o){return n(),a("div",null,s[0]||(s[0]=[e(`

🛣️ Server Router

In this section, we discuss how to use the FlashServer router to manage our RequestHandler instances. 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 the FlashServer instance.

Creating a Route

To create a route, you need to call the route() method on your server's instance and specify the base path of the route, followed by your handler class,

java
// Example.java
+public class Example {
+    public static void main(String[] args) {
+        FlashServer server = new FlashServer(8080);
+        
+        server.route("/api")
+            .register(MyHandler.class);
+            
+        server.start();
+    }
+}
java
// MyHandler.java
+
+@RouteInfo(endpoint = "/hello", method = HttpMethod.GET)
+public class MyHandler extends RequestHandler {
+    public MyHandler(Request req, Response res) {
+        super(req, res);
+    }
+
+    @Override
+    public Object handle() {
+        String response = "Hello, world!";
+        return response;
+    }
+}

In the example above, we create an /api router and register the MyHandler class to handle requests on the /api/hello endpoint.

This is because the path property of the RouteInfo annotation is relative to the base path of the router, which in this case is /api.

Visiting /api/hello from your browser will result in the response Hello, world!.

`,10)]))}const E=i(t,[["render",h]]);export{c as __pageData,E as default}; diff --git a/assets/flash_index.md.CAxgiNVz.js b/assets/flash_index.md.CAxgiNVz.js new file mode 100644 index 0000000..fca40ef --- /dev/null +++ b/assets/flash_index.md.CAxgiNVz.js @@ -0,0 +1 @@ +import{_ as t,c as n,j as e,a as s,o as i}from"./chunks/framework.p2VkXzrt.js";const f=JSON.parse('{"title":"⚡ Flash","description":"","frontmatter":{"next":{"text":"Installation","link":"/flash/installation"},"banner_title":"Flash - A Modern Web Framework","banner_description":"Flash is a fast and expressive web framework written in Java.","head":[["meta",{"name":"twitter:image","content":"/assets/banner-cards/flash-index.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/flash-index.png"}],["meta",{"name":"twitter:card","content":"summary_large_image"}],["meta",{"name":"twitter:image:height","content":"1280"}],["meta",{"name":"twitter:image:width","content":"669"}],["meta",{"name":"twitter:description","content":""}]]},"headers":[],"relativePath":"flash/index.md","filePath":"flash/index.md"}'),r={name:"flash/index.md"};function o(l,a,m,d,c,h){return i(),n("div",null,a[0]||(a[0]=[e("h1",{id:"⚡-flash",tabindex:"-1"},[s("⚡ Flash "),e("a",{class:"header-anchor",href:"#⚡-flash","aria-label":'Permalink to "⚡ Flash"'},"​")],-1),e("p",null,"Flash is a simple, modern and fast expressive web framework written in Java. The project is maintained by Pixel Services and the open-source community.",-1)]))}const x=t(r,[["render",o]]);export{f as __pageData,x as default}; diff --git a/assets/flash_index.md.CAxgiNVz.lean.js b/assets/flash_index.md.CAxgiNVz.lean.js new file mode 100644 index 0000000..fca40ef --- /dev/null +++ b/assets/flash_index.md.CAxgiNVz.lean.js @@ -0,0 +1 @@ +import{_ as t,c as n,j as e,a as s,o as i}from"./chunks/framework.p2VkXzrt.js";const f=JSON.parse('{"title":"⚡ Flash","description":"","frontmatter":{"next":{"text":"Installation","link":"/flash/installation"},"banner_title":"Flash - A Modern Web Framework","banner_description":"Flash is a fast and expressive web framework written in Java.","head":[["meta",{"name":"twitter:image","content":"/assets/banner-cards/flash-index.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/flash-index.png"}],["meta",{"name":"twitter:card","content":"summary_large_image"}],["meta",{"name":"twitter:image:height","content":"1280"}],["meta",{"name":"twitter:image:width","content":"669"}],["meta",{"name":"twitter:description","content":""}]]},"headers":[],"relativePath":"flash/index.md","filePath":"flash/index.md"}'),r={name:"flash/index.md"};function o(l,a,m,d,c,h){return i(),n("div",null,a[0]||(a[0]=[e("h1",{id:"⚡-flash",tabindex:"-1"},[s("⚡ Flash "),e("a",{class:"header-anchor",href:"#⚡-flash","aria-label":'Permalink to "⚡ Flash"'},"​")],-1),e("p",null,"Flash is a simple, modern and fast expressive web framework written in Java. The project is maintained by Pixel Services and the open-source community.",-1)]))}const x=t(r,[["render",o]]);export{f as __pageData,x as default}; diff --git a/assets/index.md.sDYgKdFh.js b/assets/index.md.sDYgKdFh.js new file mode 100644 index 0000000..118add4 --- /dev/null +++ b/assets/index.md.sDYgKdFh.js @@ -0,0 +1 @@ +import{V as i}from"./chunks/theme.B0m-fXrT.js";import{c as r,j as t,a as n,G as s,k as l,o}from"./chunks/framework.p2VkXzrt.js";const b=JSON.parse('{"title":"Our Team","description":"","frontmatter":{"banner_title":"Pixel Services Documentation","banner_description":"Explore the documentation for all public Pixel Services projects","layout":"home","hero":{"name":"Pixel Services Documentation","text":"","tagline":"Explore the documentation for all public Pixel Services projects","actions":[{"theme":"brand","text":"Support Us","link":"https://buymeacoffee.com/pixelservices"},{"theme":"alt","text":"Check out our Github","link":"https://github.com/Pixel-Services"}]},"features":[{"title":"Flash","details":"Simple, modern and fast expressive web framework written in Java.","link":"/flash"},{"title":"ServerLibraries","details":"A Library made to ease server-side Fabric mod development.","link":"/serverlibraries"},{"title":"MoBot","details":"A Modular Discord Bot with a simple but efficent API.","link":"/mobot"}],"head":[["meta",{"name":"twitter:image","content":"/assets/banner-cards/index.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/index.png"}],["meta",{"name":"twitter:card","content":"summary_large_image"}],["meta",{"name":"twitter:image:height","content":"1280"}],["meta",{"name":"twitter:image:width","content":"669"}],["meta",{"name":"twitter:description","content":""}]]},"headers":[],"relativePath":"index.md","filePath":"index.md"}'),m={name:"index.md"},h=Object.assign(m,{setup(c){const a=[{avatar:"https://avatars.githubusercontent.com/u/83401018?v=4",name:"Relism",title:"Backend Developer",links:[{icon:"github",link:"https://github.com/Relism"}]},{avatar:"https://avatars.githubusercontent.com/u/69807609?v=4",name:"Sieadev",title:"Developer",links:[{icon:"github",link:"https://github.com/sieadev"}]}];return(u,e)=>(o(),r("div",null,[e[0]||(e[0]=t("br",null,null,-1)),e[1]||(e[1]=t("hr",null,null,-1)),e[2]||(e[2]=t("br",null,null,-1)),e[3]||(e[3]=t("h1",{id:"our-team",tabindex:"-1"},[n("Our Team "),t("a",{class:"header-anchor",href:"#our-team","aria-label":'Permalink to "Our Team"'},"​")],-1)),e[4]||(e[4]=t("p",null,"Say hello to the Pixel Services team !",-1)),s(l(i),{size:"small",members:a})]))}});export{b as __pageData,h as default}; diff --git a/assets/index.md.sDYgKdFh.lean.js b/assets/index.md.sDYgKdFh.lean.js new file mode 100644 index 0000000..118add4 --- /dev/null +++ b/assets/index.md.sDYgKdFh.lean.js @@ -0,0 +1 @@ +import{V as i}from"./chunks/theme.B0m-fXrT.js";import{c as r,j as t,a as n,G as s,k as l,o}from"./chunks/framework.p2VkXzrt.js";const b=JSON.parse('{"title":"Our Team","description":"","frontmatter":{"banner_title":"Pixel Services Documentation","banner_description":"Explore the documentation for all public Pixel Services projects","layout":"home","hero":{"name":"Pixel Services Documentation","text":"","tagline":"Explore the documentation for all public Pixel Services projects","actions":[{"theme":"brand","text":"Support Us","link":"https://buymeacoffee.com/pixelservices"},{"theme":"alt","text":"Check out our Github","link":"https://github.com/Pixel-Services"}]},"features":[{"title":"Flash","details":"Simple, modern and fast expressive web framework written in Java.","link":"/flash"},{"title":"ServerLibraries","details":"A Library made to ease server-side Fabric mod development.","link":"/serverlibraries"},{"title":"MoBot","details":"A Modular Discord Bot with a simple but efficent API.","link":"/mobot"}],"head":[["meta",{"name":"twitter:image","content":"/assets/banner-cards/index.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/index.png"}],["meta",{"name":"twitter:card","content":"summary_large_image"}],["meta",{"name":"twitter:image:height","content":"1280"}],["meta",{"name":"twitter:image:width","content":"669"}],["meta",{"name":"twitter:description","content":""}]]},"headers":[],"relativePath":"index.md","filePath":"index.md"}'),m={name:"index.md"},h=Object.assign(m,{setup(c){const a=[{avatar:"https://avatars.githubusercontent.com/u/83401018?v=4",name:"Relism",title:"Backend Developer",links:[{icon:"github",link:"https://github.com/Relism"}]},{avatar:"https://avatars.githubusercontent.com/u/69807609?v=4",name:"Sieadev",title:"Developer",links:[{icon:"github",link:"https://github.com/sieadev"}]}];return(u,e)=>(o(),r("div",null,[e[0]||(e[0]=t("br",null,null,-1)),e[1]||(e[1]=t("hr",null,null,-1)),e[2]||(e[2]=t("br",null,null,-1)),e[3]||(e[3]=t("h1",{id:"our-team",tabindex:"-1"},[n("Our Team "),t("a",{class:"header-anchor",href:"#our-team","aria-label":'Permalink to "Our Team"'},"​")],-1)),e[4]||(e[4]=t("p",null,"Say hello to the Pixel Services team !",-1)),s(l(i),{size:"small",members:a})]))}});export{b as __pageData,h as default}; diff --git a/flash/advanced/fullstack-development.html b/flash/advanced/fullstack-development.html index 4692323..dea5b6d 100644 --- a/flash/advanced/fullstack-development.html +++ b/flash/advanced/fullstack-development.html @@ -54,7 +54,7 @@ server.start(); } }

🚀 Package and Deploy your app!

With the frontend and backend code in place, you can now build the JAR file and deploy it to your server. The JAR file will contain both the frontend and backend code, making it easy to deploy and run your fullstack application.

All you've left to do is run the jarfile on any machine that has Java installed, and your fullstack application will be up and running!

- + \ No newline at end of file diff --git a/flash/advanced/handler-default-implementations.html b/flash/advanced/handler-default-implementations.html index 8e9e20d..638b8ac 100644 --- a/flash/advanced/handler-default-implementations.html +++ b/flash/advanced/handler-default-implementations.html @@ -142,7 +142,7 @@ return "{\"username\":\"" + user.getUsername() + "\"}"; } } - + \ No newline at end of file diff --git a/flash/core-concepts/handlers.html b/flash/core-concepts/handlers.html index 695d7b9..29c8b0c 100644 --- a/flash/core-concepts/handlers.html +++ b/flash/core-concepts/handlers.html @@ -13,7 +13,7 @@ - + @@ -25,23 +25,10 @@ -
Skip to content

📚 Handlers

In Flash, handlers are the building blocks of your application logic. They are responsible for processing incoming requests, executing the necessary logic, and generating the appropriate response.

There are several types of handlers in Flash, each serving a specific purpose and providing a different level of control over the request lifecycle. Understanding the different handler types will help you structure your application logic more effectively and make the most out of Flash's powerful routing system.

📦 Routing Behavior

Before diving into the different handler types, it's essential to understand how routing works in Flash. When a request is received by the server, Flash matches the request path and method against the registered routes to find the appropriate handler. The handler is then executed, and its response is sent back to the client.

Flash supports 3 main types of routing behaviors:

  • Literal Routing: Matches the exact path specified in the route definition.
  • Parametrized Routing: Matches paths with dynamic segments that are extracted as route parameters.
  • Dynamic Routing: Matches any path that starts with the specified prefix and is flagged with a wildcard "*" character.

📌 Handler Types

1. RequestHandler

The RequestHandler is the "standard" type of handler in Flash, it provides the most control over the request lifecycle and allows you to define custom logic for handling requests. You can extend the RequestHandler class to create custom handlers that process incoming requests and generate responses.

Because RequestHandler is an abstract class, you need to implement both the handle() method and the super constructor in your custom handler to define the logic that should be executed when a request is received.

Since RequestHandler is an abstract class, you can leverage and chain HDI's to create cleaner and more maintainable route logic (more on that in the Handler Default Implementations guide).

java

-### 2. SimpleHandler
-
-The `SimpleHandler` is a lightweight handler that allows you to define request handling logic in a single method using lambda notation.
-It is useful for simple request processing tasks that don't require the full lifecycle control provided by `RequestHandler`.
-
-To create a `SimpleHandler`, you can use the `server.get()`, `server.post()`, `server.put()`, `server.delete()` etc.
-in general, you can use the `server.<METHOD>()` methods to register the handler with the server.
-
-The arguments for these methods are the route path and a lambda expression that provides
-the request and response objects and defines the request handling logic.
-
-```java[Example]
-server.get("/hello", (req, res) -> {
-    return "Hello, World!";
-});

Both RequestHandler and SimpleHandler can specify the router behavior by the naming convention of the endpoint used to register the handler.

  • Literal Routing: /hello
    Will match exactly /hello

  • Parametrized Routing: /hello/:name
    Will match /hello/John, /hello/Alice, etc.

  • Dynamic Routing: /hello/*
    Will match /hello/../..

- +
Skip to content

📚 Handlers

In Flash, handlers are the building blocks of your application logic. They are responsible for processing incoming requests, executing the necessary logic, and generating the appropriate response.

There are several types of handlers in Flash, each serving a specific purpose and providing a different level of control over the request lifecycle. Understanding the different handler types will help you structure your application logic more effectively and make the most out of Flash's powerful routing system.

📦 Routing Behavior

Before diving into the different handler types, it's essential to understand how routing works in Flash. When a request is received by the server, Flash matches the request path and method against the registered routes to find the appropriate handler. The handler is then executed, and its response is sent back to the client.

Flash supports 3 main types of routing behaviors:

  • Literal Routing: Matches the exact path specified in the route definition.
  • Parametrized Routing: Matches paths with dynamic segments that are extracted as route parameters.
  • Dynamic Routing: Matches any path that starts with the specified prefix and is flagged with a wildcard "*" character.

📌 Handler Types

1. RequestHandler

The RequestHandler is the "standard" type of handler in Flash, it provides the most control over the request lifecycle and allows you to define custom logic for handling requests. You can extend the RequestHandler class to create custom handlers that process incoming requests and generate responses.

Because RequestHandler is an abstract class, you need to implement both the handle() method and the super constructor in your custom handler to define the logic that should be executed when a request is received.

Since RequestHandler is an abstract class, you can leverage and chain HDI's to create cleaner and more maintainable route logic (more on that in the Handler Default Implementations guide).

2. SimpleHandler

The SimpleHandler is a lightweight handler that allows you to define request handling logic in a single method using lambda notation. It is useful for simple request processing tasks that don't require the full lifecycle control provided by RequestHandler.

To create a SimpleHandler, you can use the server.get(), server.post(), server.put(), server.delete() etc. in general, you can use the server.<METHOD>() methods to register the handler with the server.

The arguments for these methods are the route path and a lambda expression that provides the request and response objects and defines the request handling logic.

java
server.get("/hello", (req, res) -> {
+    return "Hello, World!";
+});

Both RequestHandler and SimpleHandler can specify the router behavior by the naming convention of the endpoint used to register the handler.

  • Literal Routing: /hello
    Will match exactly /hello

  • Parametrized Routing: /hello/:name
    Will match /hello/John, /hello/Alice, etc.

  • Dynamic Routing: /hello/*
    Will match /hello/../..

+ \ No newline at end of file diff --git a/flash/core-concepts/request-handler.html b/flash/core-concepts/request-handler.html index e0c3b1f..c63a416 100644 --- a/flash/core-concepts/request-handler.html +++ b/flash/core-concepts/request-handler.html @@ -37,7 +37,7 @@ return response; } }

WARNING

Any logic that needs to be executed before the request handler is registered must be done within the constructor.

Request Handler methods

The RequestHandler class provides several methods that can be used to interact with the request and response objects easily and safely. Following are listed the methods available in the RequestHandler class, with a brief description of their purpose:

MethodParamsDescription
getRequestBody()noneReturns a JSONObject representation of the request body.
getSpecification()noneReturns an instance of HandlerSpecification containing all sorts of information about the handler.
expectedRequestParameter()String name, descriptionReturns an instance of ExpectedRequestParameter for the specified parameter name.
expectedBodyField()String name, descriptionReturns an instance of ExpectedBodyField for the specified field name.
expectedBodyFile()String name, descriptionReturns an instance of ExpectedBodyFile for the specified file name.

(More on the ExpectedRequestParameter, ExpectedBodyField, and ExpectedBodyFile classes in the next section).

- + \ No newline at end of file diff --git a/flash/core-concepts/request-response.html b/flash/core-concepts/request-response.html index 1c7764f..4cb8341 100644 --- a/flash/core-concepts/request-response.html +++ b/flash/core-concepts/request-response.html @@ -92,7 +92,7 @@ return "File saved at: " + myFile.getAbsolutePath(); } }

This time, you will need to use a tool like Postman to send a POST request to /helloFile with a multipart form data body containing a file named myFile. You should receive a response like File saved at: <path> where <path> is the location where the server saved the file.

- + \ No newline at end of file diff --git a/flash/core-concepts/server-router.html b/flash/core-concepts/server-router.html index 0f6b597..93f238e 100644 --- a/flash/core-concepts/server-router.html +++ b/flash/core-concepts/server-router.html @@ -13,7 +13,7 @@ - + @@ -25,7 +25,7 @@ -
Skip to content

🛣️ Server Router

In this section, we discuss how to use the FlashServer router to manage our RequestHandler instances. 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 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,

java
// Example.java
+    
Skip to content

🛣️ Server Router

In this section, we discuss how to use the FlashServer router to manage our RequestHandler instances. 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 the FlashServer instance.

Creating a Route

To create a route, you need to call the route() method on your server's instance and specify the base path of the route, followed by your handler class,

java
// Example.java
 public class Example {
     public static void main(String[] args) {
         FlashServer server = new FlashServer(8080);
@@ -49,7 +49,7 @@
         return response;
     }
 }

In the example above, we create an /api router and register the MyHandler class to handle requests on the /api/hello endpoint.

This is because the path property of the RouteInfo annotation is relative to the base path of the router, which in this case is /api.

Visiting /api/hello from your browser will result in the response Hello, world!.

- + \ No newline at end of file diff --git a/flash/core-concepts/websockets.html b/flash/core-concepts/websockets.html index 63542ea..5038e03 100644 --- a/flash/core-concepts/websockets.html +++ b/flash/core-concepts/websockets.html @@ -58,7 +58,7 @@ server.start(); } }

Interacting with Websockets sessions

The WebSocketSession object provides methods to interact with the Websocket session, such as sending messages, closing the connection, and getting the remote address and session ID.

MethodParamsDescription
getChannel()noneReturns an instance of AsynchronousSocketChannel useful for retrieving info about the client .
getRequestInfo()noneReturns an instance of RequestInfo containing all sorts of information about the request (headers, method, path etc.) .
getPath()noneReturns the path to the websocket endpoint as a String.
getId()noneReturns the id of the websocket session as a String, useful if you want to keep track of the connected clients in a custom manager.
getBuffer()noneReturns the ByteBuffer for that session.
sendMessage()String messageSends the message to the client as a String. it's up to the developer to stringify and de-stringify any data you want to send back and forth
close()noneCloses the websocket session.

NOTE

WebsocketHandler includes a setId(String id) method for overriding the default session ID. Unless you have a specific reason to change it, it's best to leave it as is.

Similarly, the setBuffer(ByteBuffer buffer) method allows you to override the default buffer. If you're unsure about this, it's recommended to keep the default setting.

- + \ No newline at end of file diff --git a/flash/file-serving/dynamic-file-server.html b/flash/file-serving/dynamic-file-server.html index e7d5156..edc2fe7 100644 --- a/flash/file-serving/dynamic-file-server.html +++ b/flash/file-serving/dynamic-file-server.html @@ -53,7 +53,7 @@ )); } } - + \ No newline at end of file diff --git a/flash/file-serving/static-file-server.html b/flash/file-serving/static-file-server.html index e125bfc..9c8b809 100644 --- a/flash/file-serving/static-file-server.html +++ b/flash/file-serving/static-file-server.html @@ -53,7 +53,7 @@ )); } } - + \ No newline at end of file diff --git a/flash/index.html b/flash/index.html index 1e1b29c..c4927e4 100644 --- a/flash/index.html +++ b/flash/index.html @@ -13,7 +13,7 @@ - + @@ -25,8 +25,8 @@ -
Skip to content

⚡ Flash

Flash is a simple, modern and fast expressive web framework written in Java. The project is maintained by Pixel Services and the open-source community.

Our Team

Say hello to the Pixel Services team !

Relism

Relism

Developer

Sieadev

Sieadev

Developer

- +
Skip to content

⚡ Flash

Flash is a simple, modern and fast expressive web framework written in Java. The project is maintained by Pixel Services and the open-source community.

+ \ No newline at end of file diff --git a/flash/introduction/installation.html b/flash/introduction/installation.html index b07ffa6..81caaf8 100644 --- a/flash/introduction/installation.html +++ b/flash/introduction/installation.html @@ -44,7 +44,7 @@ }
  • And the dependency :

    groovy
    dependencies {
         implementation 'com.pixelservices:flash:{{ latestVersion }}'
     }
  • ⚡ Latest version:
    - + \ No newline at end of file diff --git a/hashmap.json b/hashmap.json index 63e487a..2b90f06 100644 --- a/hashmap.json +++ b/hashmap.json @@ -1 +1 @@ -{"flash_advanced_fullstack-development.md":"DFJ2Nfm_","flash_advanced_handler-default-implementations.md":"ki9D2CCK","flash_core-concepts_handlers.md":"B1156l1I","flash_core-concepts_request-handler.md":"fjZWLpOw","flash_core-concepts_request-response.md":"BuTSfkDO","flash_core-concepts_server-router.md":"Dpvzqe12","flash_core-concepts_websockets.md":"ByGVX96c","flash_file-serving_dynamic-file-server.md":"DY_r4ecH","flash_file-serving_static-file-server.md":"BvN0FZB2","flash_index.md":"E5zPbZtg","flash_introduction_installation.md":"BEOKwAAp","index.md":"CgmTRI0Q","mobot_index.md":"Be0Zoetq","serverlibraries_index.md":"CeIqSPIs"} +{"flash_advanced_fullstack-development.md":"DFJ2Nfm_","flash_advanced_handler-default-implementations.md":"ki9D2CCK","flash_core-concepts_handlers.md":"BZuBmBSX","flash_core-concepts_request-handler.md":"fjZWLpOw","flash_core-concepts_request-response.md":"BuTSfkDO","flash_core-concepts_server-router.md":"DIWo49Yl","flash_core-concepts_websockets.md":"ByGVX96c","flash_file-serving_dynamic-file-server.md":"DY_r4ecH","flash_file-serving_static-file-server.md":"BvN0FZB2","flash_index.md":"CAxgiNVz","flash_introduction_installation.md":"BEOKwAAp","index.md":"sDYgKdFh","mobot_index.md":"Be0Zoetq","serverlibraries_index.md":"CeIqSPIs"} diff --git a/index.html b/index.html index 141cad9..c2d93b1 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - Pixel Services Docs + Our Team | Pixel Services Docs @@ -13,7 +13,7 @@ - + @@ -25,8 +25,8 @@ -
    Skip to content
    - +
    Skip to content

    Pixel Services Documentation

    Explore the documentation for all public Pixel Services projects




    Our Team

    Say hello to the Pixel Services team !

    Relism

    Relism

    Backend Developer

    Sieadev

    Sieadev

    Developer

    + \ No newline at end of file diff --git a/mobot/index.html b/mobot/index.html index 19ac67e..fc16109 100644 --- a/mobot/index.html +++ b/mobot/index.html @@ -26,7 +26,7 @@
    Skip to content
    - + \ No newline at end of file diff --git a/serverlibraries/index.html b/serverlibraries/index.html index c9958d2..c26d13f 100644 --- a/serverlibraries/index.html +++ b/serverlibraries/index.html @@ -26,7 +26,7 @@
    Skip to content
    - + \ No newline at end of file