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 Guide","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"}]]},"headers":[],"relativePath":"flash/server-types.md","filePath":"flash/server-types.md"}'),t={name:"flash/server-types.md"};function l(h,s,r,p,k,d){return n(),a("div",null,s[0]||(s[0]=[e(`
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.
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.
To use the internal server, you can statically import the methods from InternalFlashServer:
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
}
}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.
To create a server instance, you can simply call new FlashServer() and configure the server using the instance methods:
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:
new FlashServer("Internal");This means:
"Internal" for logging and internal management purposes.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");
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: