diff --git a/404.html b/404.html index 8043d96..c48cfe2 100644 --- a/404.html +++ b/404.html @@ -17,7 +17,7 @@
- + \ No newline at end of file diff --git a/assets/banner-cards/flash-request-handler.png b/assets/banner-cards/flash-request-handler.png new file mode 100644 index 0000000..53396a1 Binary files /dev/null and b/assets/banner-cards/flash-request-handler.png differ diff --git a/assets/banner-cards/flash-request-response.png b/assets/banner-cards/flash-request-response.png new file mode 100644 index 0000000..e656495 Binary files /dev/null and b/assets/banner-cards/flash-request-response.png differ diff --git a/assets/banner-cards/flash-server-router.png b/assets/banner-cards/flash-server-router.png new file mode 100644 index 0000000..4c6b457 Binary files /dev/null and b/assets/banner-cards/flash-server-router.png differ diff --git a/assets/banner-cards/flash-server-types.png b/assets/banner-cards/flash-server-types.png index 1a4b896..405b903 100644 Binary files a/assets/banner-cards/flash-server-types.png and b/assets/banner-cards/flash-server-types.png differ diff --git a/assets/flash_request-handler.md.Bh6_Xj69.js b/assets/flash_request-handler.md.Bh6_Xj69.js new file mode 100644 index 0000000..ff3f831 --- /dev/null +++ b/assets/flash_request-handler.md.Bh6_Xj69.js @@ -0,0 +1,16 @@ +import{_ as s,c as t,a0 as a,o as i}from"./chunks/framework.BGabeMLJ.js";const k=JSON.parse('{"title":"⚙️ Request Handler","description":"","frontmatter":{"banner_title":"Flash - Request Handler","banner_description":"Learn how to create and manage Request Handlers in Flash.","head":[["meta",{"name":"twitter:image","content":"/assets/banner-cards/flash-request-handler.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/flash-request-handler.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/request-handler.md","filePath":"flash/request-handler.md"}'),n={name:"flash/request-handler.md"};function d(h,e,l,r,o,p){return i(),t("div",null,e[0]||(e[0]=[a(`

⚙️ Request Handler

In this section, we illustrate the powerful concept of RequestHandler in Flash, which are used to handle incoming requests and generate responses.

Creating a Request Handler

To create a custom request handler, you need to extend the RequestHandler class and annotate the class with the RouteInfo annotation, specifying the HTTP method that the handler will respond to and the relative path that the handler will be registered to. The enforceNonNullBody attribute is used to specify whether the handler expects a non-null request body: by default, it is set to false. After that, you must override the handle method; The handle method is where you define the logic for processing the request and generating the response. The req (request) and res (response) objects are available in the handler to access the request data and send the response back to the client.

You must call the super constructor with the req and res objects to initialize the handler.

java
import flash.Request;
+import flash.Response;
+import flash.RequestHandler;
+
+@RouteInfo(method = HttpMethod.GET, path = "/hello", enforceNonNullBody = false)
+public class MyHandler extends RequestHandler {
+    public MyHandler(Request req, Response res) {
+        super(req, res);
+    }
+
+    @Override
+    public Object handle() {
+        String response = "Hello, world!";
+        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).

`,11)]))}const u=s(n,[["render",d]]);export{k as __pageData,u as default}; diff --git a/assets/flash_request-handler.md.Bh6_Xj69.lean.js b/assets/flash_request-handler.md.Bh6_Xj69.lean.js new file mode 100644 index 0000000..ff3f831 --- /dev/null +++ b/assets/flash_request-handler.md.Bh6_Xj69.lean.js @@ -0,0 +1,16 @@ +import{_ as s,c as t,a0 as a,o as i}from"./chunks/framework.BGabeMLJ.js";const k=JSON.parse('{"title":"⚙️ Request Handler","description":"","frontmatter":{"banner_title":"Flash - Request Handler","banner_description":"Learn how to create and manage Request Handlers in Flash.","head":[["meta",{"name":"twitter:image","content":"/assets/banner-cards/flash-request-handler.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/flash-request-handler.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/request-handler.md","filePath":"flash/request-handler.md"}'),n={name:"flash/request-handler.md"};function d(h,e,l,r,o,p){return i(),t("div",null,e[0]||(e[0]=[a(`

⚙️ Request Handler

In this section, we illustrate the powerful concept of RequestHandler in Flash, which are used to handle incoming requests and generate responses.

Creating a Request Handler

To create a custom request handler, you need to extend the RequestHandler class and annotate the class with the RouteInfo annotation, specifying the HTTP method that the handler will respond to and the relative path that the handler will be registered to. The enforceNonNullBody attribute is used to specify whether the handler expects a non-null request body: by default, it is set to false. After that, you must override the handle method; The handle method is where you define the logic for processing the request and generating the response. The req (request) and res (response) objects are available in the handler to access the request data and send the response back to the client.

You must call the super constructor with the req and res objects to initialize the handler.

java
import flash.Request;
+import flash.Response;
+import flash.RequestHandler;
+
+@RouteInfo(method = HttpMethod.GET, path = "/hello", enforceNonNullBody = false)
+public class MyHandler extends RequestHandler {
+    public MyHandler(Request req, Response res) {
+        super(req, res);
+    }
+
+    @Override
+    public Object handle() {
+        String response = "Hello, world!";
+        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).

`,11)]))}const u=s(n,[["render",d]]);export{k as __pageData,u as default}; diff --git a/assets/flash_request-response.md.gIrPmRQZ.js b/assets/flash_request-response.md.gIrPmRQZ.js new file mode 100644 index 0000000..2b56480 --- /dev/null +++ b/assets/flash_request-response.md.gIrPmRQZ.js @@ -0,0 +1,84 @@ +import{_ as i,c as e,a0 as a,o as t}from"./chunks/framework.BGabeMLJ.js";const E=JSON.parse('{"title":"📥 Request and Response","description":"","frontmatter":{"banner_title":"Flash - Request and Response","banner_description":"Unlock the power of the Request and Response objects in Flash.","head":[["meta",{"name":"twitter:image","content":"/assets/banner-cards/flash-request-response.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/flash-request-response.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/request-response.md","filePath":"flash/request-response.md"}'),n={name:"flash/request-response.md"};function l(h,s,p,k,d,r){return t(),e("div",null,s[0]||(s[0]=[a(`

📥 Request and Response

Generally speaking, in an HTTP request-response cycle, the client sends a request to the server, and the server generates a response based on the request. In this section, we illustrate the Request and Response objects in Flash, which are used to interact with the request data and generate responses. We will learn to read and interpret the request data, and model the correct response to send back to the client.

Request and Response Objects

The Request and Response objects are passed to the handler constructor and provide access to the request data and response methods. Under the hood, these objects are provided by the RouteController during the registration stage of the handler, and they are continously updated for each request on that specific handler's instance, but for now, you can consider them as magic.

These objects are a very powerful tool to interact with the lifecycle of the server's response, and they provide a wide range of methods that makes our lives as developers easier.

RequestHandler context

Inside a RequestHandler class, you can access the Request and Response objects inside the handle method by simply typing req and res, respectively. You can use the methods provided by these objects both outside of a handler, and inside of it, to interact with the request and response objects. Although, the advantages of being inside a handler are that Flash supports out-of-the-box methods that can significantly clean up your code and improve the overall readability of your handlers.

Specifically, the ExpectedRequestParameter, ExpectedBodyField, and ExpectedBodyFile objects are used to get the expected properties of the request, and they are used by Flash to validate the request data before the handle method is even executed.

The developer can then simply assume that all the expected parameters are present and valid, without having to write a single line of validation code: Flash will do it for you.

The three objects mentioned above are fairly similar in their usage, providing getter methods which safely return the data in the expected format and type, thanks to Flash's built-in validation and casting system.

NOTE

Flash will take care of informing the client of any missing or invalid parameters, parameters that are not in the expected format, or any other kind of error that might occur during the validation process.

REMEMBER

The ExpectedRequestParameter, ExpectedBodyField, and ExpectedBodyFile instances are ONLY supposed to be retrieved by calling the respective expectedRequestParameter(), expectedBodyField(), and expectedBodyFile() methods INSIDE of the super constructor of your handler class.

Example Usage

Click to expand

The ExpectedRequestParameter object is used to get the expected parameters of the request. You can use the getter methods to safely get the parameter value, such as getString, getInt, getDouble, and getBoolean methods to safely cast the parameter to the expected type.

java
import flash.Request;
+import flash.Response;
+import flash.models.RequestHandler;
+import flash.models.ExpectedRequestParameter;
+
+@RouteInfo(method = HttpMethod.GET, path = "/hello", enforceNonNullBody = false)
+public class MyHandler extends RequestHandler {
+    // Store the expected parameter in a private field
+    private final ExpectedRequestParameter myExpectedReqParam;
+    public MyHandler(Request req, Response res) {
+        super(req, res);
+        // Get the expected parameter "myParam", and optionally provide a description
+        myExpectedReqParam = expectedRequestParameter("myParam", "A description of the parameter");
+    }
+
+    @Override
+    public Object handle() {
+        // OPTIONAL: specify the response status code and type
+        res.status(200);
+        res.type("text/plain");
+        
+        // Safely get the parameter value as a String
+        String myParamValue = myExpectedReqParam.getString();
+        
+        // Return the response to the client
+        return "Hello, " + myParamValue + "!";
+    }
+}

Visiting /hello?myParam=John from your browser, will return Hello, John!.

Click to expand

The ExpectedBodyField object is used to get the expected fields of the request body. You can use the getter methods to safely get the field value, such as getString, getInt, getDouble, and getBoolean methods to safely cast the field to the expected type.

java
import flash.Request;
+import flash.Response;
+import flash.models.RequestHandler;
+import flash.models.ExpectedBodyField;
+
+// Make sure to set enforceNonNullBody to true
+@RouteInfo(method = HttpMethod.GET, path = "/helloBody", enforceNonNullBody = true)
+public class MyHandler extends RequestHandler {
+    // Store the expected field in a private field
+    private final ExpectedBodyField myExpectedBodyField;
+    public MyHandler(Request req, Response res) {
+        super(req, res);
+        // Get the expected field "myField", and optionally provide a description
+        myExpectedBodyField = expectedBodyField("myField", "A description of the field");
+    }
+
+    @Override
+    public Object handle() {
+        // OPTIONAL: specify the response status code and type
+        res.status(200);
+        res.type("text/plain");
+        
+        // Safely get the field value as a String
+        String myFieldValue = myExpectedBodyField.getString();
+        
+        // Return the response to the client
+        return "Field value: " + myFieldValue;
+    }
+}

This time, since we are expecting a field in the request body, using our browser would not be enough to test the handler. Instead, you can use a tool like Postman to send a GET request to /helloBody with a multipart form data body containing a field named myField. You should receive a response like Field value: <value>.

Click to expand

The ExpectedBodyFile object is used to get the expected files of the request body. The methods provided by this object are slightly different from the other two, but still extremely powerful and simple to use.

java
import flash.Request;
+import flash.Response;
+import flash.models.RequestHandler;
+import flash.models.ExpectedBodyFile;
+
+// Make sure to set enforceNonNullBody to true
+@RouteInfo(method = HttpMethod.POST, path = "/helloFile", enforceNonNullBody = true)
+public class MyHandler extends RequestHandler {
+    // Store the expected file in a private field
+    private final ExpectedBodyFile myExpectedBodyFile;
+    public MyHandler(Request req, Response res) {
+        super(req, res);
+        // Get the expected file "myFile", and optionally provide a description
+        myExpectedBodyFile = expectedBodyFile("myFile", "A description of the file");
+    }
+
+    @Override
+    public Object handle() {
+        // OPTIONAL: specify the response status code and type
+        res.status(200);
+        res.type("text/plain");
+        
+        // Write the file to filesystem and get the File object
+        File myFile = myExpectedBodyFile.createFile(Paths.get("path/to/save"));
+        
+        // Return the response to the client
+        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.

`,19)]))}const c=i(n,[["render",l]]);export{E as __pageData,c as default}; diff --git a/assets/flash_request-response.md.gIrPmRQZ.lean.js b/assets/flash_request-response.md.gIrPmRQZ.lean.js new file mode 100644 index 0000000..2b56480 --- /dev/null +++ b/assets/flash_request-response.md.gIrPmRQZ.lean.js @@ -0,0 +1,84 @@ +import{_ as i,c as e,a0 as a,o as t}from"./chunks/framework.BGabeMLJ.js";const E=JSON.parse('{"title":"📥 Request and Response","description":"","frontmatter":{"banner_title":"Flash - Request and Response","banner_description":"Unlock the power of the Request and Response objects in Flash.","head":[["meta",{"name":"twitter:image","content":"/assets/banner-cards/flash-request-response.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/flash-request-response.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/request-response.md","filePath":"flash/request-response.md"}'),n={name:"flash/request-response.md"};function l(h,s,p,k,d,r){return t(),e("div",null,s[0]||(s[0]=[a(`

📥 Request and Response

Generally speaking, in an HTTP request-response cycle, the client sends a request to the server, and the server generates a response based on the request. In this section, we illustrate the Request and Response objects in Flash, which are used to interact with the request data and generate responses. We will learn to read and interpret the request data, and model the correct response to send back to the client.

Request and Response Objects

The Request and Response objects are passed to the handler constructor and provide access to the request data and response methods. Under the hood, these objects are provided by the RouteController during the registration stage of the handler, and they are continously updated for each request on that specific handler's instance, but for now, you can consider them as magic.

These objects are a very powerful tool to interact with the lifecycle of the server's response, and they provide a wide range of methods that makes our lives as developers easier.

RequestHandler context

Inside a RequestHandler class, you can access the Request and Response objects inside the handle method by simply typing req and res, respectively. You can use the methods provided by these objects both outside of a handler, and inside of it, to interact with the request and response objects. Although, the advantages of being inside a handler are that Flash supports out-of-the-box methods that can significantly clean up your code and improve the overall readability of your handlers.

Specifically, the ExpectedRequestParameter, ExpectedBodyField, and ExpectedBodyFile objects are used to get the expected properties of the request, and they are used by Flash to validate the request data before the handle method is even executed.

The developer can then simply assume that all the expected parameters are present and valid, without having to write a single line of validation code: Flash will do it for you.

The three objects mentioned above are fairly similar in their usage, providing getter methods which safely return the data in the expected format and type, thanks to Flash's built-in validation and casting system.

NOTE

Flash will take care of informing the client of any missing or invalid parameters, parameters that are not in the expected format, or any other kind of error that might occur during the validation process.

REMEMBER

The ExpectedRequestParameter, ExpectedBodyField, and ExpectedBodyFile instances are ONLY supposed to be retrieved by calling the respective expectedRequestParameter(), expectedBodyField(), and expectedBodyFile() methods INSIDE of the super constructor of your handler class.

Example Usage

Click to expand

The ExpectedRequestParameter object is used to get the expected parameters of the request. You can use the getter methods to safely get the parameter value, such as getString, getInt, getDouble, and getBoolean methods to safely cast the parameter to the expected type.

java
import flash.Request;
+import flash.Response;
+import flash.models.RequestHandler;
+import flash.models.ExpectedRequestParameter;
+
+@RouteInfo(method = HttpMethod.GET, path = "/hello", enforceNonNullBody = false)
+public class MyHandler extends RequestHandler {
+    // Store the expected parameter in a private field
+    private final ExpectedRequestParameter myExpectedReqParam;
+    public MyHandler(Request req, Response res) {
+        super(req, res);
+        // Get the expected parameter "myParam", and optionally provide a description
+        myExpectedReqParam = expectedRequestParameter("myParam", "A description of the parameter");
+    }
+
+    @Override
+    public Object handle() {
+        // OPTIONAL: specify the response status code and type
+        res.status(200);
+        res.type("text/plain");
+        
+        // Safely get the parameter value as a String
+        String myParamValue = myExpectedReqParam.getString();
+        
+        // Return the response to the client
+        return "Hello, " + myParamValue + "!";
+    }
+}

Visiting /hello?myParam=John from your browser, will return Hello, John!.

Click to expand

The ExpectedBodyField object is used to get the expected fields of the request body. You can use the getter methods to safely get the field value, such as getString, getInt, getDouble, and getBoolean methods to safely cast the field to the expected type.

java
import flash.Request;
+import flash.Response;
+import flash.models.RequestHandler;
+import flash.models.ExpectedBodyField;
+
+// Make sure to set enforceNonNullBody to true
+@RouteInfo(method = HttpMethod.GET, path = "/helloBody", enforceNonNullBody = true)
+public class MyHandler extends RequestHandler {
+    // Store the expected field in a private field
+    private final ExpectedBodyField myExpectedBodyField;
+    public MyHandler(Request req, Response res) {
+        super(req, res);
+        // Get the expected field "myField", and optionally provide a description
+        myExpectedBodyField = expectedBodyField("myField", "A description of the field");
+    }
+
+    @Override
+    public Object handle() {
+        // OPTIONAL: specify the response status code and type
+        res.status(200);
+        res.type("text/plain");
+        
+        // Safely get the field value as a String
+        String myFieldValue = myExpectedBodyField.getString();
+        
+        // Return the response to the client
+        return "Field value: " + myFieldValue;
+    }
+}

This time, since we are expecting a field in the request body, using our browser would not be enough to test the handler. Instead, you can use a tool like Postman to send a GET request to /helloBody with a multipart form data body containing a field named myField. You should receive a response like Field value: <value>.

Click to expand

The ExpectedBodyFile object is used to get the expected files of the request body. The methods provided by this object are slightly different from the other two, but still extremely powerful and simple to use.

java
import flash.Request;
+import flash.Response;
+import flash.models.RequestHandler;
+import flash.models.ExpectedBodyFile;
+
+// Make sure to set enforceNonNullBody to true
+@RouteInfo(method = HttpMethod.POST, path = "/helloFile", enforceNonNullBody = true)
+public class MyHandler extends RequestHandler {
+    // Store the expected file in a private field
+    private final ExpectedBodyFile myExpectedBodyFile;
+    public MyHandler(Request req, Response res) {
+        super(req, res);
+        // Get the expected file "myFile", and optionally provide a description
+        myExpectedBodyFile = expectedBodyFile("myFile", "A description of the file");
+    }
+
+    @Override
+    public Object handle() {
+        // OPTIONAL: specify the response status code and type
+        res.status(200);
+        res.type("text/plain");
+        
+        // Write the file to filesystem and get the File object
+        File myFile = myExpectedBodyFile.createFile(Paths.get("path/to/save"));
+        
+        // Return the response to the client
+        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.

`,19)]))}const c=i(n,[["render",l]]);export{E as __pageData,c as default}; diff --git a/assets/flash_server-router.md.DthG-_ys.js b/assets/flash_server-router.md.DthG-_ys.js new file mode 100644 index 0000000..5374286 --- /dev/null +++ b/assets/flash_server-router.md.DthG-_ys.js @@ -0,0 +1,29 @@ +import{_ as i,c as a,a0 as e,o as n}from"./chunks/framework.BGabeMLJ.js";const E=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-server-router.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/flash-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/server-router.md","filePath":"flash/server-router.md"}'),t={name:"flash/server-router.md"};function h(l,s,p,r,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 either the internal server or your 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.

(More on the concept of RouteInterceptor in the following sections).

java
// Example.java
+import static flash.InternalFlashServer.*;
+
+public class Example {
+    public static void main(String[] args) {
+        port(8080);
+        
+        route("/api")
+            .register(MyHandler.class);
+            
+        start();
+    }
+}
java
// MyHandler.java
+import flash.Request;
+import flash.Response;
+import flash.models.RequestHandler;
+
+@RouteInfo(method = HttpMethod.GET, path = "/hello", enforceNonNullBody = false)
+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 a route /api 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 route, which in this case is /api.

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

`,11)]))}const c=i(t,[["render",h]]);export{E as __pageData,c as default}; diff --git a/assets/flash_server-router.md.DthG-_ys.lean.js b/assets/flash_server-router.md.DthG-_ys.lean.js new file mode 100644 index 0000000..5374286 --- /dev/null +++ b/assets/flash_server-router.md.DthG-_ys.lean.js @@ -0,0 +1,29 @@ +import{_ as i,c as a,a0 as e,o as n}from"./chunks/framework.BGabeMLJ.js";const E=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-server-router.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/flash-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/server-router.md","filePath":"flash/server-router.md"}'),t={name:"flash/server-router.md"};function h(l,s,p,r,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 either the internal server or your 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.

(More on the concept of RouteInterceptor in the following sections).

java
// Example.java
+import static flash.InternalFlashServer.*;
+
+public class Example {
+    public static void main(String[] args) {
+        port(8080);
+        
+        route("/api")
+            .register(MyHandler.class);
+            
+        start();
+    }
+}
java
// MyHandler.java
+import flash.Request;
+import flash.Response;
+import flash.models.RequestHandler;
+
+@RouteInfo(method = HttpMethod.GET, path = "/hello", enforceNonNullBody = false)
+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 a route /api 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 route, which in this case is /api.

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

`,11)]))}const c=i(t,[["render",h]]);export{E as __pageData,c as default}; diff --git a/assets/flash_server-types.md.Bq9J39sx.js b/assets/flash_server-types.md.Bq9J39sx.js new file mode 100644 index 0000000..1d95f8e --- /dev/null +++ b/assets/flash_server-types.md.Bq9J39sx.js @@ -0,0 +1,37 @@ +import{_ as i,c as a,a0 as e,o as n}from"./chunks/framework.BGabeMLJ.js";const E=JSON.parse('{"title":"Server Types","description":"","frontmatter":{"banner_title":"Flash - Server Types","banner_description":"Illustrating the main differences between the internal server instance and the FlashServer instance.","head":[["meta",{"name":"twitter:image","content":"/assets/banner-cards/flash-server-types.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/flash-server-types.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/server-types.md","filePath":"flash/server-types.md"}'),t={name:"flash/server-types.md"};function h(l,s,r,p,k,d){return n(),a("div",null,s[0]||(s[0]=[e(`

Server Types

In this section, we discuss the differences between the internal server instance InternalFlashServer and the FlashServer instance, and whether you should use one or the other. We will also provide examples of how to use each type of server.

Internal Server

The internal server is a singleton instance that can be accessed by statically importing methods from InternalFlashServer. This means that for each application, only one InternalFlashServer instance is created. This allows you to use the server's functionality without creating and managing an instance of the server.

Usage

To use the internal server, you can statically import the methods from InternalFlashServer:

java
import static flash.InternalFlashServer.*;
+
+public class Example {
+    public static void main(String[] args) {
+        port(8080);
+        
+        get("/hello", (req, res) -> {
+            res.status(200);
+            return "Hello, world!";
+        });
+
+        post("/submit", (req, res) -> {
+            // Handle POST request
+        });
+
+        // Other routes and configurations
+    }
+}

Server Instance

The FlashServer class is used to create an instance of the server. Unlike the internal server, you can create multiple instances of the FlashServer class with different configurations.

Usage

To create a server instance, you can simply call new FlashServer() and configure the server using the instance methods:

java
import flash.FlashServer;
+
+public class Example {
+    public static void main(String[] args) {
+        FlashServer server = new FlashServer("My Server Instance");
+
+        server.port(8080);
+        
+        server.get("/hello", (req, res) -> {
+            res.status(200);
+            return "Hello, world!";
+        });
+
+        server.post("/submit", (req, res) -> {
+            // Handle POST request
+        });
+
+        // Other routes and configurations
+    }
+}

The InternalFlashServer is a pre-configured instance of FlashServer that is managed internally by the library. Under the hood, it is instantiated as:

java
new FlashServer("Internal");

This means:

Both the InternalFlashServer and any user-created FlashServer instances are of the same type (FlashServer). However, if you want to create and manage your own server instance, you must provide a name during initialization, e.g.:

java
FlashServer server = new FlashServer("My Server Instance");

Which Server Type Should You Use?

It all depends on your use case. If you only need one server instance and want to keep your code concise, you can use the internal server. However, if your application needs to handle multiple server instances each with different ports and configurations, you should use FlashServer instances.

WARNING

From now on, and unless otherwise specified, every example in the documentation will use the InternalFlashServer to illustrate the usage of the library. However, for your specific implementation, you can call the same methods on your FlashServer instance to achieve the same results.

`,21)]))}const c=i(t,[["render",h]]);export{E as __pageData,c as default}; diff --git a/assets/flash_server-types.md.Bq9J39sx.lean.js b/assets/flash_server-types.md.Bq9J39sx.lean.js new file mode 100644 index 0000000..1d95f8e --- /dev/null +++ b/assets/flash_server-types.md.Bq9J39sx.lean.js @@ -0,0 +1,37 @@ +import{_ as i,c as a,a0 as e,o as n}from"./chunks/framework.BGabeMLJ.js";const E=JSON.parse('{"title":"Server Types","description":"","frontmatter":{"banner_title":"Flash - Server Types","banner_description":"Illustrating the main differences between the internal server instance and the FlashServer instance.","head":[["meta",{"name":"twitter:image","content":"/assets/banner-cards/flash-server-types.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/flash-server-types.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/server-types.md","filePath":"flash/server-types.md"}'),t={name:"flash/server-types.md"};function h(l,s,r,p,k,d){return n(),a("div",null,s[0]||(s[0]=[e(`

Server Types

In this section, we discuss the differences between the internal server instance InternalFlashServer and the FlashServer instance, and whether you should use one or the other. We will also provide examples of how to use each type of server.

Internal Server

The internal server is a singleton instance that can be accessed by statically importing methods from InternalFlashServer. This means that for each application, only one InternalFlashServer instance is created. This allows you to use the server's functionality without creating and managing an instance of the server.

Usage

To use the internal server, you can statically import the methods from InternalFlashServer:

java
import static flash.InternalFlashServer.*;
+
+public class Example {
+    public static void main(String[] args) {
+        port(8080);
+        
+        get("/hello", (req, res) -> {
+            res.status(200);
+            return "Hello, world!";
+        });
+
+        post("/submit", (req, res) -> {
+            // Handle POST request
+        });
+
+        // Other routes and configurations
+    }
+}

Server Instance

The FlashServer class is used to create an instance of the server. Unlike the internal server, you can create multiple instances of the FlashServer class with different configurations.

Usage

To create a server instance, you can simply call new FlashServer() and configure the server using the instance methods:

java
import flash.FlashServer;
+
+public class Example {
+    public static void main(String[] args) {
+        FlashServer server = new FlashServer("My Server Instance");
+
+        server.port(8080);
+        
+        server.get("/hello", (req, res) -> {
+            res.status(200);
+            return "Hello, world!";
+        });
+
+        server.post("/submit", (req, res) -> {
+            // Handle POST request
+        });
+
+        // Other routes and configurations
+    }
+}

The InternalFlashServer is a pre-configured instance of FlashServer that is managed internally by the library. Under the hood, it is instantiated as:

java
new FlashServer("Internal");

This means:

Both the InternalFlashServer and any user-created FlashServer instances are of the same type (FlashServer). However, if you want to create and manage your own server instance, you must provide a name during initialization, e.g.:

java
FlashServer server = new FlashServer("My Server Instance");

Which Server Type Should You Use?

It all depends on your use case. If you only need one server instance and want to keep your code concise, you can use the internal server. However, if your application needs to handle multiple server instances each with different ports and configurations, you should use FlashServer instances.

WARNING

From now on, and unless otherwise specified, every example in the documentation will use the InternalFlashServer to illustrate the usage of the library. However, for your specific implementation, you can call the same methods on your FlashServer instance to achieve the same results.

`,21)]))}const c=i(t,[["render",h]]);export{E as __pageData,c as default}; diff --git a/flash/index.html b/flash/index.html index 30571f6..5c28519 100644 --- a/flash/index.html +++ b/flash/index.html @@ -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.

Our Team

Say hello to the Pixel Services team !

Relism

Relism

Developer

Sieadev

Sieadev

Developer

+ \ No newline at end of file diff --git a/flash/installation.html b/flash/installation.html index b2d590d..d147f0f 100644 --- a/flash/installation.html +++ b/flash/installation.html @@ -25,7 +25,7 @@ -
Skip to content

📲 Installation

This page provides installation instructions for the latest version of the flash library from Pixel Services.

Installation

Maven (pom.xml)

  1. Add the repository :

    xml
    <repositories>
    +    
    Skip to content

    📲 Installation

    This page provides installation instructions for the latest version of the flash library from Pixel Services.

    Installation

    Maven (pom.xml)

    1. Add the repository :

      xml
      <repositories>
         <repository>
           <id>pixel-services</id>
           <name>Pixel Services</name>
      @@ -44,7 +44,7 @@
       }
    2. And the dependency :

      groovy
      dependencies {
           implementation 'com.pixelservices:flash:{{ latestVersion }}'
       }
    ⚡ Latest version:
    - + \ No newline at end of file diff --git a/flash/request-handler.html b/flash/request-handler.html new file mode 100644 index 0000000..fe84147 --- /dev/null +++ b/flash/request-handler.html @@ -0,0 +1,47 @@ + + + + + + ⚙️ Request Handler | Pixel Services Docs + + + + + + + + + + + + + + + + + + + + + +
    Skip to content

    ⚙️ Request Handler

    In this section, we illustrate the powerful concept of RequestHandler in Flash, which are used to handle incoming requests and generate responses.

    Creating a Request Handler

    To create a custom request handler, you need to extend the RequestHandler class and annotate the class with the RouteInfo annotation, specifying the HTTP method that the handler will respond to and the relative path that the handler will be registered to. The enforceNonNullBody attribute is used to specify whether the handler expects a non-null request body: by default, it is set to false. After that, you must override the handle method; The handle method is where you define the logic for processing the request and generating the response. The req (request) and res (response) objects are available in the handler to access the request data and send the response back to the client.

    You must call the super constructor with the req and res objects to initialize the handler.

    java
    import flash.Request;
    +import flash.Response;
    +import flash.RequestHandler;
    +
    +@RouteInfo(method = HttpMethod.GET, path = "/hello", enforceNonNullBody = false)
    +public class MyHandler extends RequestHandler {
    +    public MyHandler(Request req, Response res) {
    +        super(req, res);
    +    }
    +
    +    @Override
    +    public Object handle() {
    +        String response = "Hello, world!";
    +        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/request-response.html b/flash/request-response.html new file mode 100644 index 0000000..6bab87e --- /dev/null +++ b/flash/request-response.html @@ -0,0 +1,115 @@ + + + + + + 📥 Request and Response | Pixel Services Docs + + + + + + + + + + + + + + + + + + + + + +
    Skip to content

    📥 Request and Response

    Generally speaking, in an HTTP request-response cycle, the client sends a request to the server, and the server generates a response based on the request. In this section, we illustrate the Request and Response objects in Flash, which are used to interact with the request data and generate responses. We will learn to read and interpret the request data, and model the correct response to send back to the client.

    Request and Response Objects

    The Request and Response objects are passed to the handler constructor and provide access to the request data and response methods. Under the hood, these objects are provided by the RouteController during the registration stage of the handler, and they are continously updated for each request on that specific handler's instance, but for now, you can consider them as magic.

    These objects are a very powerful tool to interact with the lifecycle of the server's response, and they provide a wide range of methods that makes our lives as developers easier.

    RequestHandler context

    Inside a RequestHandler class, you can access the Request and Response objects inside the handle method by simply typing req and res, respectively. You can use the methods provided by these objects both outside of a handler, and inside of it, to interact with the request and response objects. Although, the advantages of being inside a handler are that Flash supports out-of-the-box methods that can significantly clean up your code and improve the overall readability of your handlers.

    Specifically, the ExpectedRequestParameter, ExpectedBodyField, and ExpectedBodyFile objects are used to get the expected properties of the request, and they are used by Flash to validate the request data before the handle method is even executed.

    The developer can then simply assume that all the expected parameters are present and valid, without having to write a single line of validation code: Flash will do it for you.

    The three objects mentioned above are fairly similar in their usage, providing getter methods which safely return the data in the expected format and type, thanks to Flash's built-in validation and casting system.

    NOTE

    Flash will take care of informing the client of any missing or invalid parameters, parameters that are not in the expected format, or any other kind of error that might occur during the validation process.

    REMEMBER

    The ExpectedRequestParameter, ExpectedBodyField, and ExpectedBodyFile instances are ONLY supposed to be retrieved by calling the respective expectedRequestParameter(), expectedBodyField(), and expectedBodyFile() methods INSIDE of the super constructor of your handler class.

    Example Usage

    • ExpectedRequestParameter
    Click to expand

    The ExpectedRequestParameter object is used to get the expected parameters of the request. You can use the getter methods to safely get the parameter value, such as getString, getInt, getDouble, and getBoolean methods to safely cast the parameter to the expected type.

    java
    import flash.Request;
    +import flash.Response;
    +import flash.models.RequestHandler;
    +import flash.models.ExpectedRequestParameter;
    +
    +@RouteInfo(method = HttpMethod.GET, path = "/hello", enforceNonNullBody = false)
    +public class MyHandler extends RequestHandler {
    +    // Store the expected parameter in a private field
    +    private final ExpectedRequestParameter myExpectedReqParam;
    +    public MyHandler(Request req, Response res) {
    +        super(req, res);
    +        // Get the expected parameter "myParam", and optionally provide a description
    +        myExpectedReqParam = expectedRequestParameter("myParam", "A description of the parameter");
    +    }
    +
    +    @Override
    +    public Object handle() {
    +        // OPTIONAL: specify the response status code and type
    +        res.status(200);
    +        res.type("text/plain");
    +        
    +        // Safely get the parameter value as a String
    +        String myParamValue = myExpectedReqParam.getString();
    +        
    +        // Return the response to the client
    +        return "Hello, " + myParamValue + "!";
    +    }
    +}

    Visiting /hello?myParam=John from your browser, will return Hello, John!.

    • ExpectedBodyField
    Click to expand

    The ExpectedBodyField object is used to get the expected fields of the request body. You can use the getter methods to safely get the field value, such as getString, getInt, getDouble, and getBoolean methods to safely cast the field to the expected type.

    java
    import flash.Request;
    +import flash.Response;
    +import flash.models.RequestHandler;
    +import flash.models.ExpectedBodyField;
    +
    +// Make sure to set enforceNonNullBody to true
    +@RouteInfo(method = HttpMethod.GET, path = "/helloBody", enforceNonNullBody = true)
    +public class MyHandler extends RequestHandler {
    +    // Store the expected field in a private field
    +    private final ExpectedBodyField myExpectedBodyField;
    +    public MyHandler(Request req, Response res) {
    +        super(req, res);
    +        // Get the expected field "myField", and optionally provide a description
    +        myExpectedBodyField = expectedBodyField("myField", "A description of the field");
    +    }
    +
    +    @Override
    +    public Object handle() {
    +        // OPTIONAL: specify the response status code and type
    +        res.status(200);
    +        res.type("text/plain");
    +        
    +        // Safely get the field value as a String
    +        String myFieldValue = myExpectedBodyField.getString();
    +        
    +        // Return the response to the client
    +        return "Field value: " + myFieldValue;
    +    }
    +}

    This time, since we are expecting a field in the request body, using our browser would not be enough to test the handler. Instead, you can use a tool like Postman to send a GET request to /helloBody with a multipart form data body containing a field named myField. You should receive a response like Field value: <value>.

    • ExpectedBodyFile
    Click to expand

    The ExpectedBodyFile object is used to get the expected files of the request body. The methods provided by this object are slightly different from the other two, but still extremely powerful and simple to use.

    • createFile(Path/String) accepts either a Path or a String as input. It writes the file's contents to the specified location on the filesystem and returns a File object for further interaction.
    • getFileName() simply returns the name of the file specified by the client.
    • getInputStream() returns an InputStream object containing the file's contents.
    java
    import flash.Request;
    +import flash.Response;
    +import flash.models.RequestHandler;
    +import flash.models.ExpectedBodyFile;
    +
    +// Make sure to set enforceNonNullBody to true
    +@RouteInfo(method = HttpMethod.POST, path = "/helloFile", enforceNonNullBody = true)
    +public class MyHandler extends RequestHandler {
    +    // Store the expected file in a private field
    +    private final ExpectedBodyFile myExpectedBodyFile;
    +    public MyHandler(Request req, Response res) {
    +        super(req, res);
    +        // Get the expected file "myFile", and optionally provide a description
    +        myExpectedBodyFile = expectedBodyFile("myFile", "A description of the file");
    +    }
    +
    +    @Override
    +    public Object handle() {
    +        // OPTIONAL: specify the response status code and type
    +        res.status(200);
    +        res.type("text/plain");
    +        
    +        // Write the file to filesystem and get the File object
    +        File myFile = myExpectedBodyFile.createFile(Paths.get("path/to/save"));
    +        
    +        // Return the response to the client
    +        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/server-router.html b/flash/server-router.html new file mode 100644 index 0000000..e784d09 --- /dev/null +++ b/flash/server-router.html @@ -0,0 +1,60 @@ + + + + + + 🛣️ Server Router | Pixel Services Docs + + + + + + + + + + + + + + + + + + + + + +
    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 either the internal server or your 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.

    (More on the concept of RouteInterceptor in the following sections).

    java
    // Example.java
    +import static flash.InternalFlashServer.*;
    +
    +public class Example {
    +    public static void main(String[] args) {
    +        port(8080);
    +        
    +        route("/api")
    +            .register(MyHandler.class);
    +            
    +        start();
    +    }
    +}
    java
    // MyHandler.java
    +import flash.Request;
    +import flash.Response;
    +import flash.models.RequestHandler;
    +
    +@RouteInfo(method = HttpMethod.GET, path = "/hello", enforceNonNullBody = false)
    +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 a route /api 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 route, 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/server-types.html b/flash/server-types.html index 0a03dcd..728d568 100644 --- a/flash/server-types.html +++ b/flash/server-types.html @@ -13,7 +13,7 @@ - + @@ -25,7 +25,7 @@ -
    Skip to content

    Server Types

    In this section, we discuss the differences between the internal server instance InternalFlashServer and the FlashServer instance, and whether you should use one or the other. We will also provide examples of how to use each type of server.

    Internal Server

    The internal server is a singleton instance that can be accessed by statically importing methods from InternalFlashServer. This means that for each application, only one InternalFlashServer instance is created. This allows you to use the server's functionality without creating and managing an instance of the server.

    Usage

    To use the internal server, you can statically import the methods from InternalFlashServer:

    java
    import static flash.InternalFlashServer.*;
    +    
    Skip to content

    Server Types

    In this section, we discuss the differences between the internal server instance InternalFlashServer and the FlashServer instance, and whether you should use one or the other. We will also provide examples of how to use each type of server.

    Internal Server

    The internal server is a singleton instance that can be accessed by statically importing methods from InternalFlashServer. This means that for each application, only one InternalFlashServer instance is created. This allows you to use the server's functionality without creating and managing an instance of the server.

    Usage

    To use the internal server, you can statically import the methods from InternalFlashServer:

    java
    import static flash.InternalFlashServer.*;
     
     public class Example {
         public static void main(String[] args) {
    @@ -61,8 +61,8 @@
     
             // Other routes and configurations
         }
    -}

    The InternalFlashServer is a pre-configured instance of FlashServer that is managed internally by the library. Under the hood, it is instantiated as:

    java
    new FlashServer("Internal");

    This means:

    • Its name is set to "Internal" for logging and internal management purposes.
    • It serves as the default server used by the library, which is automatically initialized when the library is loaded.

    Both the InternalFlashServer and any user-created FlashServer instances are of the same type (FlashServer). However, if you want to create and manage your own server instance, you must provide a name during initialization, e.g.:

    FlashServer server = new FlashServer("My Server Instance");

    Which Server Type Should You Use?

    It all depends on your use case. If you only need one server instance and want to keep your code concise, you can use the internal server. However, if your application needs to handle multiple server instances each with different ports and configurations, you should use FlashServer instances.

    Example use cases for each server type:

    • Internal Server: Simple Backend for a webapp.
    • Server Instance: Applications where flexible deployment and scalability are required.
    - +}

    The InternalFlashServer is a pre-configured instance of FlashServer that is managed internally by the library. Under the hood, it is instantiated as:

    java
    new FlashServer("Internal");

    This means:

    • Its name is set to "Internal" for logging and internal management purposes.
    • It serves as the default server used by the library, which is automatically initialized when the library is loaded.

    Both the InternalFlashServer and any user-created FlashServer instances are of the same type (FlashServer). However, if you want to create and manage your own server instance, you must provide a name during initialization, e.g.:

    java
    FlashServer server = new FlashServer("My Server Instance");

    Which Server Type Should You Use?

    It all depends on your use case. If you only need one server instance and want to keep your code concise, you can use the internal server. However, if your application needs to handle multiple server instances each with different ports and configurations, you should use FlashServer instances.

    WARNING

    From now on, and unless otherwise specified, every example in the documentation will use the InternalFlashServer to illustrate the usage of the library. However, for your specific implementation, you can call the same methods on your FlashServer instance to achieve the same results.

    + \ No newline at end of file diff --git a/hashmap.json b/hashmap.json index 3bcdda2..fd344a7 100644 --- a/hashmap.json +++ b/hashmap.json @@ -1 +1 @@ -{"flash_index.md":"BZydQnCn","flash_installation.md":"BILQfhgS","flash_server-types.md":"fr-GJoQm","index.md":"CKSOJSRs","mobot_index.md":"CdigA9Ng","serverlibraries_index.md":"CnbDNesW"} +{"flash_index.md":"BZydQnCn","flash_installation.md":"BILQfhgS","flash_request-handler.md":"Bh6_Xj69","flash_request-response.md":"gIrPmRQZ","flash_server-router.md":"DthG-_ys","flash_server-types.md":"Bq9J39sx","index.md":"CKSOJSRs","mobot_index.md":"CdigA9Ng","serverlibraries_index.md":"CnbDNesW"} diff --git a/index.html b/index.html index f8a6197..bf2af6b 100644 --- a/index.html +++ b/index.html @@ -26,7 +26,7 @@ - + \ No newline at end of file diff --git a/mobot/index.html b/mobot/index.html index ceaec14..a863d56 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 43ebc02..e4fc328 100644 --- a/serverlibraries/index.html +++ b/serverlibraries/index.html @@ -26,7 +26,7 @@
    Skip to content
    - + \ No newline at end of file