From 976e27afbf6180137ae28a5ffaeb157b333964e7 Mon Sep 17 00:00:00 2001 From: ballerina-bot Date: Fri, 31 Jan 2025 08:50:15 +0000 Subject: [PATCH] Update ballerina standard library specifications --- public/spec/http/spec.md | 35 +++++++++++++++++++++++++++++++++++ spec/http/spec.md | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/public/spec/http/spec.md b/public/spec/http/spec.md index 320f09d9e493..efffbe5ea692 100644 --- a/public/spec/http/spec.md +++ b/public/spec/http/spec.md @@ -23,6 +23,7 @@ The conforming implementation of the specification is released and included in t * 2.1. [Listener](#21-listener) * 2.1.1. [Automatically starting the service](#211-automatically-starting-the-service) * 2.1.2. [Programmatically starting the service](#212-programmatically-starting-the-service) + * 2.1.3. [Default listener](#213-default-listener) * 2.2. [Service](#22-service) * 2.2.1. [Service type](#221-service-type) * 2.2.2. [Service-base-path](#222-service-base-path) @@ -212,6 +213,40 @@ http:Service s = service object { }; ``` +#### 2.1.3. Default listener + +The default listener can be created by calling the `getDefaultListener()` method. Once the default listener is created, +the subsequent calls to the `getDefaultListener()` method will return the same listener object. With this approach, +the user can attach multiple services to the same listener and configure the listener as required. The default listener +port is 9090. + +```ballerina +import ballerina/http; + +listener http:Listener httpListener = http:getDefaultListener(); + +service /api/v1 on httpListener { + + resource function get greeting() returns string { + return "Hello, World from Service 1!"; + } +} +``` + +The port and listener configuration of the default listener can be changed in the `Config.toml` as follows: + +```toml +[ballerina.http] +defaultListenerPort = 8080 + +[ballerina.http.defaultListenerConfig] +httpVersion = "1.1" + +[ballerina.http.defaultListenerConfig.secureSocket.key] +path = "resources/certs/ballerinaKeystore.p12" +password = "ballerina" +``` + ### 2.2. Service Service is a collection of resources functions, which are the network entry points of a ballerina program. In addition to that a service can contain public and private functions which can be accessed by calling with `self`. diff --git a/spec/http/spec.md b/spec/http/spec.md index 320f09d9e493..efffbe5ea692 100644 --- a/spec/http/spec.md +++ b/spec/http/spec.md @@ -23,6 +23,7 @@ The conforming implementation of the specification is released and included in t * 2.1. [Listener](#21-listener) * 2.1.1. [Automatically starting the service](#211-automatically-starting-the-service) * 2.1.2. [Programmatically starting the service](#212-programmatically-starting-the-service) + * 2.1.3. [Default listener](#213-default-listener) * 2.2. [Service](#22-service) * 2.2.1. [Service type](#221-service-type) * 2.2.2. [Service-base-path](#222-service-base-path) @@ -212,6 +213,40 @@ http:Service s = service object { }; ``` +#### 2.1.3. Default listener + +The default listener can be created by calling the `getDefaultListener()` method. Once the default listener is created, +the subsequent calls to the `getDefaultListener()` method will return the same listener object. With this approach, +the user can attach multiple services to the same listener and configure the listener as required. The default listener +port is 9090. + +```ballerina +import ballerina/http; + +listener http:Listener httpListener = http:getDefaultListener(); + +service /api/v1 on httpListener { + + resource function get greeting() returns string { + return "Hello, World from Service 1!"; + } +} +``` + +The port and listener configuration of the default listener can be changed in the `Config.toml` as follows: + +```toml +[ballerina.http] +defaultListenerPort = 8080 + +[ballerina.http.defaultListenerConfig] +httpVersion = "1.1" + +[ballerina.http.defaultListenerConfig.secureSocket.key] +path = "resources/certs/ballerinaKeystore.p12" +password = "ballerina" +``` + ### 2.2. Service Service is a collection of resources functions, which are the network entry points of a ballerina program. In addition to that a service can contain public and private functions which can be accessed by calling with `self`.