Module http.default
tharmigank/http.default
Overview
This module provides a built-in HTTP listener that serves as the default implementation for creating HTTP servers. It allows multiple services to be attached and supports customization of its port and configuration, making it versatile for various use cases.
Key Features
- Built-in listener for convenient HTTP service setup.
- Supports attaching multiple services, making it suitable for centralized deployment.
- Fully customizable port and listener configuration.
Usage Example
The following example demonstrates how to use the default HTTP listener to create an HTTP server:
import ballerina/http.default;
service /api on default:httpListener {
resource function get greeting() returns string { return "Hello, World!"; }
}
Customizing the Listener Port
By default, the listener uses port 9090. To change this, specify the desired port in the Config.toml
file as shown below:
[ballerina.http.default] listenerPort = 8080
Configuring the Listener
You can customize all HTTP listener configuration in the Config.toml
file. For detailed instructions on configuring variables, refer to the Configurability guide.
The following example configures the HTTP listener to use HTTP/1.1 and enables SSL:
[ballerina.http.default.listenerConfig] httpVersion = "1.1" [ballerina.http.default.listenerConfig.secureSocket.key] path = "resources/certs/key.pem" password = "password"