-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
100 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
## Overview | ||
|
||
This module provides a built-in HTTP listener that serves as the default listener for attaching HTTP servers. It supports the attachment of multiple services, making it ideal for centralized deployment. Additionally, it allows for the customization of its port and configuration, offering versatility for various use cases. | ||
|
||
## Usage Example | ||
|
||
The following example demonstrates how to use the default HTTP listener to create an HTTP server: | ||
|
||
```ballerina | ||
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: | ||
|
||
```toml | ||
[ballerina.http.default] | ||
listenerPort = 8080 | ||
``` | ||
|
||
## Configuring the Listener | ||
|
||
You can customize all [HTTP listener configuration](https://central.ballerina.io/ballerina/http/latest#ListenerConfiguration) in the `Config.toml` file. For detailed instructions on configuring variables, refer to the [Configurability](https://ballerina.io/learn/provide-values-to-configurable-variables/) guide. | ||
|
||
The following example configures the HTTP listener to use HTTP/1.1 and enables SSL: | ||
|
||
```toml | ||
[ballerina.http.default.listenerConfig] | ||
httpVersion = "1.1" | ||
|
||
[ballerina.http.default.listenerConfig.secureSocket.key] | ||
path = "resources/certs/key.pem" | ||
password = "password" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2025 WSO2 Inc. (http://www.wso2.org). | ||
// | ||
// WSO2 Inc. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import ballerina/http; | ||
|
||
# Represents the port that the default HTTP listener should be bound to. | ||
# The default port is 9090 | ||
public configurable int listenerPort = 9090; | ||
|
||
# Represents the listener configuration that should be used by the default HTTP listener | ||
public configurable http:ListenerConfiguration listenerConfig = {}; | ||
|
||
# Represents the default HTTP listener that can be used by multiple services | ||
public listener http:Listener httpListener = check new (listenerPort, listenerConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters