Interface WebhookServer
- All Superinterfaces:
AutoCloseable,Closeable
This class defines the basic functionality for a webhook server that can be started, configured with POST routes, and closed.
The server is expected to listen for incoming HTTP POST requests and invoke the appropriate handlers based on the path of the request.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddPostRoute(@NotNull String path, @NotNull Function<String, HttpResponse> response) Adds a POST route to the server with a specific path and an associated handler.static @NotNull WebhookServerinternal(@NotNull WebhookServerConfig config, @NotNull WebhookBotSettings botSettings) Internal factory method for creating a WebhookServer instance.booleanChecks if the server is running.voidremovePostRoute(@NotNull String path) Removes a previously added POST route from the server.voidstart()Starts the webhook server, allowing it to begin accepting incoming requests.
-
Method Details
-
internal
@Internal @NotNull static @NotNull WebhookServer internal(@NotNull @NotNull WebhookServerConfig config, @NotNull @NotNull WebhookBotSettings botSettings) Internal factory method for creating a WebhookServer instance.This method should only be used internally and should not be accessed directly by external users of the API.
- Parameters:
config- The configuration to initialize the server with. Cannot be null.- Returns:
- A new instance of
SunWebhookServerImpl.
-
start
Starts the webhook server, allowing it to begin accepting incoming requests.This method should be called once the server has been properly configured. It will initiate the necessary network connections and begin listening for incoming HTTP requests. After calling this method, the server will be ready to handle requests.
- Throws:
Exception- If an error occurs while starting the server.
-
addPostRoute
void addPostRoute(@NotNull @NotNull String path, @NotNull @NotNull Function<String, HttpResponse> response) throws ExceptionAdds a POST route to the server with a specific path and an associated handler.This method registers a POST route at the specified path. When the server receives a POST request on this path, the provided handler will be invoked. The handler is asynchronous and is expected to handle the HTTP request asynchronously.
- Parameters:
path- The path of the route to add. Cannot be null or empty.response- The handler function to invoke when a POST request is received. The function takes the body of the POST request as input and returns an HTTP response. Cannot be null.- Throws:
Exception- If an error occurs while adding the route.
-
removePostRoute
Removes a previously added POST route from the server.This method removes the POST route at the specified path, so that the server will no longer respond to POST requests at that path.
- Parameters:
path- The path of the route to remove. Cannot be null or empty.- Throws:
Exception- If an error occurs while removing the route.
-
isRunning
boolean isRunning()Checks if the server is running.- Returns:
trueif the server is running,falseotherwise.
-