From a691d85db1ae18e8d7fefc03cebb204ef9b5e175 Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Fri, 2 Aug 2024 14:14:25 +0530 Subject: [PATCH 01/12] Update http timestamp version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 4db768d55a..5c13b1abc4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -57,7 +57,7 @@ stdlibTomlVersion=0.5.1 stdlibYamlVersion=0.5.3 # Stdlib Level 05 -stdlibHttpVersion=2.11.1 +stdlibHttpVersion=2.12.0-20240801-081400-0b676d6 # Stdlib Level 06 stdlibGrpcVersion=1.11.1 From 16b756e948eb3b2df2e579b986a3ea24552386d8 Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Fri, 2 Aug 2024 14:14:42 +0530 Subject: [PATCH 02/12] Add Server-Sent Events BBE --- examples/http-sse-client/http_sse_client.bal | 11 ++++++++ .../http_sse_client.client.out | 7 +++++ examples/http-sse-client/http_sse_client.md | 16 +++++++++++ .../http-sse-client/http_sse_client.metatags | 2 ++ .../http-sse-service/http_sse_service.bal | 25 +++++++++++++++++ .../http_sse_service.client.out | 27 +++++++++++++++++++ examples/http-sse-service/http_sse_service.md | 17 ++++++++++++ .../http_sse_service.metatags | 2 ++ .../http_sse_service.server.out | 1 + examples/index.json | 16 +++++++++++ 10 files changed, 124 insertions(+) create mode 100644 examples/http-sse-client/http_sse_client.bal create mode 100644 examples/http-sse-client/http_sse_client.client.out create mode 100644 examples/http-sse-client/http_sse_client.md create mode 100644 examples/http-sse-client/http_sse_client.metatags create mode 100644 examples/http-sse-service/http_sse_service.bal create mode 100644 examples/http-sse-service/http_sse_service.client.out create mode 100644 examples/http-sse-service/http_sse_service.md create mode 100644 examples/http-sse-service/http_sse_service.metatags create mode 100644 examples/http-sse-service/http_sse_service.server.out diff --git a/examples/http-sse-client/http_sse_client.bal b/examples/http-sse-client/http_sse_client.bal new file mode 100644 index 0000000000..f629f2a623 --- /dev/null +++ b/examples/http-sse-client/http_sse_client.bal @@ -0,0 +1,11 @@ +import ballerina/http; +import ballerina/io; + +public function main() returns error? { + http:Client clientEp = check new ("localhost:9090"); + stream eventStream = check clientEp->/stocks; + check from http:SseEvent event in eventStream + do { + io:println("Stock price: ", event.data); + }; +} diff --git a/examples/http-sse-client/http_sse_client.client.out b/examples/http-sse-client/http_sse_client.client.out new file mode 100644 index 0000000000..7bbe45371e --- /dev/null +++ b/examples/http-sse-client/http_sse_client.client.out @@ -0,0 +1,7 @@ +$ bal run http_sse_client.bal + +Stock price: 249.9963321685791 +Stock price: 56.58070945739746 +Stock price: 571.2127494812012 +Stock price: 217.98820853233337 +Stock price: 21.891758739948273 diff --git a/examples/http-sse-client/http_sse_client.md b/examples/http-sse-client/http_sse_client.md new file mode 100644 index 0000000000..ad61cbcf0f --- /dev/null +++ b/examples/http-sse-client/http_sse_client.md @@ -0,0 +1,16 @@ +# HTTP client - Server-Sent Events + +The `http:Client` in Ballerina supports receiving real-time data from services using Server-Sent Events (SSE). It allows payload-binding of a stream of `http:SseEvent` when consuming SSE from a service. This payload binding fails if the content type header is not present in the response or does not have the value `text/event-stream`. + +::: code http_sse_client.bal ::: + +## Prerequisites +- Run the HTTP service given in the [Server-Sent Events](/learn/by-example/http-sse-service/) example. + +Run the client program by executing the command below. + +::: out http_sse_client.client.out ::: + +## Related links +- [`http` module - API documentation](https://lib.ballerina.io/ballerina/http/latest/) +- [Client action return types - Specification](/spec/http/#243-client-action-return-types) diff --git a/examples/http-sse-client/http_sse_client.metatags b/examples/http-sse-client/http_sse_client.metatags new file mode 100644 index 0000000000..6ecc547e17 --- /dev/null +++ b/examples/http-sse-client/http_sse_client.metatags @@ -0,0 +1,2 @@ +description: This example demonstrates how Server-Sent Events (SSE) can be consumed using an HTTP client. +keywords: ballerina, ballerina by example, bbe, http, SSE, client diff --git a/examples/http-sse-service/http_sse_service.bal b/examples/http-sse-service/http_sse_service.bal new file mode 100644 index 0000000000..d675e21370 --- /dev/null +++ b/examples/http-sse-service/http_sse_service.bal @@ -0,0 +1,25 @@ +import ballerina/http; +import ballerina/lang.runtime; +import ballerina/random; + +service /stocks on new http:Listener(9090) { + resource function get .() returns stream { + StockPriceEventGenerator generator = new; + return new (generator); + } +} + +class StockPriceEventGenerator { + int i = 0; + + public isolated function next() returns record {|http:SseEvent value;|}|error? { + if self.i == 5 { + return (); + } + self.i += 1; + runtime:sleep(1); + float stockPrice = (check random:createIntInRange(1, 1000)) * random:createDecimal(); + http:SseEvent event = {data: stockPrice.toString()}; + return {value: event}; + } +} diff --git a/examples/http-sse-service/http_sse_service.client.out b/examples/http-sse-service/http_sse_service.client.out new file mode 100644 index 0000000000..fd4a450513 --- /dev/null +++ b/examples/http-sse-service/http_sse_service.client.out @@ -0,0 +1,27 @@ +$ curl -v localhost:9090/stocks +* Trying [::1]:9090... +* Connected to localhost (::1) port 9090 +> GET /stocks/stockA HTTP/1.1 +> Host: localhost:9090 +> User-Agent: curl/8.4.0 +> Accept: */* +> +< HTTP/1.1 200 OK +< content-type: text/event-stream +< cache-control: no-cache,public +< transfer-encoding: chunked +< connection: keep-alive +< server: ballerina +< date: Fri, 2 Aug 2024 12:02:04 +0530 +< +data: 76.6014928817749 + +data: 789.1765828132629 + +data: 241.89215344190598 + +data: 494.8120536804199 + +data: 234.36854779720306 + +* Connection #0 to host localhost left intact diff --git a/examples/http-sse-service/http_sse_service.md b/examples/http-sse-service/http_sse_service.md new file mode 100644 index 0000000000..b58bee0572 --- /dev/null +++ b/examples/http-sse-service/http_sse_service.md @@ -0,0 +1,17 @@ +# HTTP service - Server-Sent Events + +The `http:Service` in Ballerina supports pushing real-time data to clients using Server-Sent Events (SSE). A stream of `http:SseEvent` can be returned from service resource methods. This feature automatically handles sending SSE and sets the content type to text/event-stream, and the transfer encoding is automatically set to chunked. + +::: code http_sse_service.bal ::: + +Run the service program by executing the following command. + +::: out http_sse_service.server.out ::: + +Invoke the service by executing the following cURL command in a new terminal. + +::: out http_sse_service.client.out ::: + +## Related links +- [`http` module - API documentation](https://lib.ballerina.io/ballerina/http/latest/) +- [Resource return types - Specification](/spec/http/#235-return-types) diff --git a/examples/http-sse-service/http_sse_service.metatags b/examples/http-sse-service/http_sse_service.metatags new file mode 100644 index 0000000000..f075c84467 --- /dev/null +++ b/examples/http-sse-service/http_sse_service.metatags @@ -0,0 +1,2 @@ +description: This example demonstrates how Server-Sent Events (SSE) can be produced using an HTTP service. +keywords: ballerina, ballerina by example, bbe, http, SSE, service diff --git a/examples/http-sse-service/http_sse_service.server.out b/examples/http-sse-service/http_sse_service.server.out new file mode 100644 index 0000000000..96b8248f5f --- /dev/null +++ b/examples/http-sse-service/http_sse_service.server.out @@ -0,0 +1 @@ +$ bal run http_sse_service.bal diff --git a/examples/index.json b/examples/index.json index 7c568b7077..78fd8ac03a 100644 --- a/examples/index.json +++ b/examples/index.json @@ -2256,6 +2256,14 @@ "verifyOutput": false, "disablePlayground": false, "isLearnByExample": false + }, + { + "name": "Server-Sent Events", + "url": "http-sse-service", + "verifyBuild": true, + "verifyOutput": false, + "disablePlayground": false, + "isLearnByExample": false } ] }, @@ -2327,6 +2335,14 @@ "verifyOutput": false, "disablePlayground": false, "isLearnByExample": false + }, + { + "name": "Server-Sent Events", + "url": "http-sse-client", + "verifyBuild": true, + "verifyOutput": false, + "disablePlayground": false, + "isLearnByExample": false } ] }, From c7d5964f0558485278c7951e59d6f0d5459a490a Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Fri, 2 Aug 2024 14:24:35 +0530 Subject: [PATCH 03/12] Update crypto, jwt and mime versions --- gradle.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5c13b1abc4..7cdd7fc342 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,7 +25,7 @@ stdlibMathVectorVersion=1.0.2 # Stdlib Level 02 stdlibAvroVersion=1.0.0 stdlibConstraintVersion=1.5.0 -stdlibCryptoVersion=2.7.0 +stdlibCryptoVersion=2.7.2 stdlibDataXmldataVersion=0.1.4 stdlibLogVersion=2.9.0 stdlibOsVersion=1.8.0 @@ -40,7 +40,7 @@ observeInternalVersion=1.2.2 stdlibCacheVersion=3.8.0 stdlibFileVersion=1.9.0 stdlibFtpVersion=2.10.1 -stdlibMimeVersion=2.9.0 +stdlibMimeVersion=2.10.0-20240724-124600-f193322 stdlibTcpVersion=1.10.0 stdlibUdpVersion=1.10.0 stdlibUuidVersion=1.8.0 @@ -50,7 +50,7 @@ stdlibAuthVersion=2.11.0 stdlibDataJsondataVersion=0.1.0 stdlibEdiVersion=1.2.0 stdlibEmailVersion=2.9.0 -stdlibJwtVersion=2.11.0 +stdlibJwtVersion=2.12.1 stdlibMqttVersion=1.1.1 stdlibOAuth2Version=2.11.0 stdlibTomlVersion=0.5.1 From bc20a340e973a2fe6bd0cfff03292ead9b80cfe5 Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Fri, 2 Aug 2024 14:26:13 +0530 Subject: [PATCH 04/12] Rename variable --- examples/http-sse-service/http_sse_service.bal | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/http-sse-service/http_sse_service.bal b/examples/http-sse-service/http_sse_service.bal index d675e21370..38d08f3889 100644 --- a/examples/http-sse-service/http_sse_service.bal +++ b/examples/http-sse-service/http_sse_service.bal @@ -10,13 +10,13 @@ service /stocks on new http:Listener(9090) { } class StockPriceEventGenerator { - int i = 0; + int eventCounter = 0; public isolated function next() returns record {|http:SseEvent value;|}|error? { - if self.i == 5 { + if self.eventCounter == 5 { return (); } - self.i += 1; + self.eventCounter += 1; runtime:sleep(1); float stockPrice = (check random:createIntInRange(1, 1000)) * random:createDecimal(); http:SseEvent event = {data: stockPrice.toString()}; From 83c772bda74ab82ff9119b62fdbc7f231a260065 Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Mon, 5 Aug 2024 16:34:47 +0530 Subject: [PATCH 05/12] Update examples/http-sse-client/http_sse_client.md Co-authored-by: Maryam Ziyad --- examples/http-sse-client/http_sse_client.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/http-sse-client/http_sse_client.md b/examples/http-sse-client/http_sse_client.md index ad61cbcf0f..d9210dcdc5 100644 --- a/examples/http-sse-client/http_sse_client.md +++ b/examples/http-sse-client/http_sse_client.md @@ -7,7 +7,7 @@ The `http:Client` in Ballerina supports receiving real-time data from services u ## Prerequisites - Run the HTTP service given in the [Server-Sent Events](/learn/by-example/http-sse-service/) example. -Run the client program by executing the command below. +Run the client program by executing the following command.. ::: out http_sse_client.client.out ::: From 7c5f26d9cd2ccd58343d95d517b2f6798f8374e6 Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Mon, 5 Aug 2024 16:38:22 +0530 Subject: [PATCH 06/12] Address review suggestions --- examples/http-sse-client/http_sse_client.md | 4 ++-- examples/http-sse-service/http_sse_service.md | 4 ++-- examples/index.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/http-sse-client/http_sse_client.md b/examples/http-sse-client/http_sse_client.md index d9210dcdc5..51121cd7ba 100644 --- a/examples/http-sse-client/http_sse_client.md +++ b/examples/http-sse-client/http_sse_client.md @@ -1,11 +1,11 @@ -# HTTP client - Server-Sent Events +# HTTP client - Server-sent events The `http:Client` in Ballerina supports receiving real-time data from services using Server-Sent Events (SSE). It allows payload-binding of a stream of `http:SseEvent` when consuming SSE from a service. This payload binding fails if the content type header is not present in the response or does not have the value `text/event-stream`. ::: code http_sse_client.bal ::: ## Prerequisites -- Run the HTTP service given in the [Server-Sent Events](/learn/by-example/http-sse-service/) example. +- Run the HTTP service given in the [Server-sent events](/learn/by-example/http-sse-service/) example. Run the client program by executing the following command.. diff --git a/examples/http-sse-service/http_sse_service.md b/examples/http-sse-service/http_sse_service.md index b58bee0572..fc4e4224c3 100644 --- a/examples/http-sse-service/http_sse_service.md +++ b/examples/http-sse-service/http_sse_service.md @@ -1,6 +1,6 @@ -# HTTP service - Server-Sent Events +# HTTP service - Server-sent events -The `http:Service` in Ballerina supports pushing real-time data to clients using Server-Sent Events (SSE). A stream of `http:SseEvent` can be returned from service resource methods. This feature automatically handles sending SSE and sets the content type to text/event-stream, and the transfer encoding is automatically set to chunked. +The `http:Service` in Ballerina supports pushing real-time data to clients using Server-Sent Events (SSE). A stream of `http:SseEvent` can be returned from service resource methods. This feature automatically handles sending SSE and sets the content type to `text/event-stream`, and the transfer encoding is automatically set to chunked. ::: code http_sse_service.bal ::: diff --git a/examples/index.json b/examples/index.json index 78fd8ac03a..b77f1db7a2 100644 --- a/examples/index.json +++ b/examples/index.json @@ -2258,7 +2258,7 @@ "isLearnByExample": false }, { - "name": "Server-Sent Events", + "name": "Server-sent events", "url": "http-sse-service", "verifyBuild": true, "verifyOutput": false, @@ -2337,7 +2337,7 @@ "isLearnByExample": false }, { - "name": "Server-Sent Events", + "name": "Server-sent events", "url": "http-sse-client", "verifyBuild": true, "verifyOutput": false, From da3254c5db738bd7a437059d8199a73dfdd87ee3 Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Mon, 12 Aug 2024 09:29:20 +0530 Subject: [PATCH 07/12] Address review suggestions --- examples/http-sse-client/http_sse_client.md | 4 ++-- examples/http-sse-client/http_sse_client.metatags | 2 +- examples/http-sse-service/http_sse_service.md | 2 +- examples/http-sse-service/http_sse_service.metatags | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/http-sse-client/http_sse_client.md b/examples/http-sse-client/http_sse_client.md index 51121cd7ba..cd39aa58d8 100644 --- a/examples/http-sse-client/http_sse_client.md +++ b/examples/http-sse-client/http_sse_client.md @@ -1,13 +1,13 @@ # HTTP client - Server-sent events -The `http:Client` in Ballerina supports receiving real-time data from services using Server-Sent Events (SSE). It allows payload-binding of a stream of `http:SseEvent` when consuming SSE from a service. This payload binding fails if the content type header is not present in the response or does not have the value `text/event-stream`. +The `http:Client` in Ballerina supports receiving real-time data from services using Server-sent events (SSE). It allows payload-binding of a stream of `http:SseEvent` when consuming SSE from a service. This payload binding fails if the content type header is not present in the response or does not have the value `text/event-stream`. ::: code http_sse_client.bal ::: ## Prerequisites - Run the HTTP service given in the [Server-sent events](/learn/by-example/http-sse-service/) example. -Run the client program by executing the following command.. +Run the client program by executing the following command. ::: out http_sse_client.client.out ::: diff --git a/examples/http-sse-client/http_sse_client.metatags b/examples/http-sse-client/http_sse_client.metatags index 6ecc547e17..42ecab8e50 100644 --- a/examples/http-sse-client/http_sse_client.metatags +++ b/examples/http-sse-client/http_sse_client.metatags @@ -1,2 +1,2 @@ -description: This example demonstrates how Server-Sent Events (SSE) can be consumed using an HTTP client. +description: This example demonstrates how Server-sent events (SSE) can be consumed using an HTTP client. keywords: ballerina, ballerina by example, bbe, http, SSE, client diff --git a/examples/http-sse-service/http_sse_service.md b/examples/http-sse-service/http_sse_service.md index fc4e4224c3..5637c04467 100644 --- a/examples/http-sse-service/http_sse_service.md +++ b/examples/http-sse-service/http_sse_service.md @@ -1,6 +1,6 @@ # HTTP service - Server-sent events -The `http:Service` in Ballerina supports pushing real-time data to clients using Server-Sent Events (SSE). A stream of `http:SseEvent` can be returned from service resource methods. This feature automatically handles sending SSE and sets the content type to `text/event-stream`, and the transfer encoding is automatically set to chunked. +Ballerina HTTP services support pushing real-time data to clients using Server-event events (SSE). A stream of type `http:SseEvent` can be returned from service resource methods. This feature automatically handles sending SSE and sets the content type to `text/event-stream` and the transfer encoding to chunked. ::: code http_sse_service.bal ::: diff --git a/examples/http-sse-service/http_sse_service.metatags b/examples/http-sse-service/http_sse_service.metatags index f075c84467..41c96c9452 100644 --- a/examples/http-sse-service/http_sse_service.metatags +++ b/examples/http-sse-service/http_sse_service.metatags @@ -1,2 +1,2 @@ -description: This example demonstrates how Server-Sent Events (SSE) can be produced using an HTTP service. +description: This example demonstrates how Server-sent events (SSE) can be produced using an HTTP service. keywords: ballerina, ballerina by example, bbe, http, SSE, service From faa16418bf1be9ac71c397183b6c5d9b5c968790 Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Mon, 12 Aug 2024 09:54:29 +0530 Subject: [PATCH 08/12] Add comments in http_sse_service.bal --- examples/http-sse-service/http_sse_service.bal | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/http-sse-service/http_sse_service.bal b/examples/http-sse-service/http_sse_service.bal index 38d08f3889..8d0ec828fb 100644 --- a/examples/http-sse-service/http_sse_service.bal +++ b/examples/http-sse-service/http_sse_service.bal @@ -3,21 +3,27 @@ import ballerina/lang.runtime; import ballerina/random; service /stocks on new http:Listener(9090) { + // This function returns a stream of SSE with stock prices resource function get .() returns stream { + // Create a new instance of StockPriceEventGenerator to generate stock price events StockPriceEventGenerator generator = new; + // Return a new stream that uses the generator to produce events return new (generator); } } +// Define a class to generate stock price events class StockPriceEventGenerator { int eventCounter = 0; public isolated function next() returns record {|http:SseEvent value;|}|error? { + // If the eventCounter reaches 5, stop generating events by returning nil if self.eventCounter == 5 { return (); } self.eventCounter += 1; runtime:sleep(1); + // Generate a random stock price float stockPrice = (check random:createIntInRange(1, 1000)) * random:createDecimal(); http:SseEvent event = {data: stockPrice.toString()}; return {value: event}; From 53444d30c76050d824d377b6390a1be765439032 Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Mon, 12 Aug 2024 10:51:43 +0530 Subject: [PATCH 09/12] Apply suggestions from code review Co-authored-by: Maryam Ziyad --- examples/http-sse-client/http_sse_client.md | 2 +- examples/http-sse-service/http_sse_service.bal | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/http-sse-client/http_sse_client.md b/examples/http-sse-client/http_sse_client.md index cd39aa58d8..965b57dfc0 100644 --- a/examples/http-sse-client/http_sse_client.md +++ b/examples/http-sse-client/http_sse_client.md @@ -1,6 +1,6 @@ # HTTP client - Server-sent events -The `http:Client` in Ballerina supports receiving real-time data from services using Server-sent events (SSE). It allows payload-binding of a stream of `http:SseEvent` when consuming SSE from a service. This payload binding fails if the content type header is not present in the response or does not have the value `text/event-stream`. +The HTTP client supports receiving real-time data from services using server-sent events (SSE). It allows payload-binding of a stream of `http:SseEvent` when consuming SSE from a service. This payload binding fails if the content type header is not present in the response or does not have the value `text/event-stream`. ::: code http_sse_client.bal ::: diff --git a/examples/http-sse-service/http_sse_service.bal b/examples/http-sse-service/http_sse_service.bal index 8d0ec828fb..96b26a7d71 100644 --- a/examples/http-sse-service/http_sse_service.bal +++ b/examples/http-sse-service/http_sse_service.bal @@ -3,21 +3,23 @@ import ballerina/lang.runtime; import ballerina/random; service /stocks on new http:Listener(9090) { - // This function returns a stream of SSE with stock prices + // This resource method returns a stream of `http:SseEvent` (with stock prices) + // to push real-time data to clients using server-event events (SSE). resource function get .() returns stream { - // Create a new instance of StockPriceEventGenerator to generate stock price events + // Create a new value of type `StockPriceEventGenerator` to generate stock price events. StockPriceEventGenerator generator = new; - // Return a new stream that uses the generator to produce events + // Return a new stream that uses the generator to produce events. return new (generator); } } -// Define a class to generate stock price events +// Define a stream implementor that can be used to create a stream +// of `http:SseEvent`, representing stock price events. class StockPriceEventGenerator { int eventCounter = 0; public isolated function next() returns record {|http:SseEvent value;|}|error? { - // If the eventCounter reaches 5, stop generating events by returning nil + // If the eventCounter reaches 5, stop generating events by returning nil. if self.eventCounter == 5 { return (); } From e0f39bde0dcd855577651ae4c6f68e1ea7bdc682 Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Mon, 12 Aug 2024 10:54:50 +0530 Subject: [PATCH 10/12] Address review suggestions --- examples/http-sse-client/http_sse_client.metatags | 2 +- examples/http-sse-service/http_sse_service.metatags | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/http-sse-client/http_sse_client.metatags b/examples/http-sse-client/http_sse_client.metatags index 42ecab8e50..9740375c90 100644 --- a/examples/http-sse-client/http_sse_client.metatags +++ b/examples/http-sse-client/http_sse_client.metatags @@ -1,2 +1,2 @@ -description: This example demonstrates how Server-sent events (SSE) can be consumed using an HTTP client. +description: This example demonstrates how server-sent events (SSE) can be consumed using an HTTP client. keywords: ballerina, ballerina by example, bbe, http, SSE, client diff --git a/examples/http-sse-service/http_sse_service.metatags b/examples/http-sse-service/http_sse_service.metatags index 41c96c9452..4a89b28a4d 100644 --- a/examples/http-sse-service/http_sse_service.metatags +++ b/examples/http-sse-service/http_sse_service.metatags @@ -1,2 +1,2 @@ -description: This example demonstrates how Server-sent events (SSE) can be produced using an HTTP service. +description: This example demonstrates how server-sent events (SSE) can be produced using an HTTP service. keywords: ballerina, ballerina by example, bbe, http, SSE, service From 54580a7cecf69fd4a85d3ec4711182387a8be3a0 Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Mon, 12 Aug 2024 11:27:45 +0530 Subject: [PATCH 11/12] Add comments in http_sse_client.bal --- examples/http-sse-client/http_sse_client.bal | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/http-sse-client/http_sse_client.bal b/examples/http-sse-client/http_sse_client.bal index f629f2a623..71b858f42a 100644 --- a/examples/http-sse-client/http_sse_client.bal +++ b/examples/http-sse-client/http_sse_client.bal @@ -3,7 +3,9 @@ import ballerina/io; public function main() returns error? { http:Client clientEp = check new ("localhost:9090"); + // Make a GET request to the "/stocks" endpoint and receive a stream of `http:SseEvent`. stream eventStream = check clientEp->/stocks; + // Iterate over the stream and handle each event. check from http:SseEvent event in eventStream do { io:println("Stock price: ", event.data); From 2ed9e3121f045b33ab51d5818be0c0358ef85240 Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Wed, 14 Aug 2024 17:59:09 +0530 Subject: [PATCH 12/12] Apply suggestions from code review Co-authored-by: Maryam Ziyad --- examples/http-sse-service/http_sse_service.bal | 2 +- examples/http-sse-service/http_sse_service.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/http-sse-service/http_sse_service.bal b/examples/http-sse-service/http_sse_service.bal index 96b26a7d71..f8c44f62f8 100644 --- a/examples/http-sse-service/http_sse_service.bal +++ b/examples/http-sse-service/http_sse_service.bal @@ -4,7 +4,7 @@ import ballerina/random; service /stocks on new http:Listener(9090) { // This resource method returns a stream of `http:SseEvent` (with stock prices) - // to push real-time data to clients using server-event events (SSE). + // to push real-time data to clients using server-sent events (SSE). resource function get .() returns stream { // Create a new value of type `StockPriceEventGenerator` to generate stock price events. StockPriceEventGenerator generator = new; diff --git a/examples/http-sse-service/http_sse_service.md b/examples/http-sse-service/http_sse_service.md index 5637c04467..352626bbab 100644 --- a/examples/http-sse-service/http_sse_service.md +++ b/examples/http-sse-service/http_sse_service.md @@ -1,6 +1,6 @@ # HTTP service - Server-sent events -Ballerina HTTP services support pushing real-time data to clients using Server-event events (SSE). A stream of type `http:SseEvent` can be returned from service resource methods. This feature automatically handles sending SSE and sets the content type to `text/event-stream` and the transfer encoding to chunked. +Ballerina HTTP services support pushing real-time data to clients using server-sent events (SSE). A stream of type `http:SseEvent` can be returned from service resource methods. This feature automatically handles sending SSE and sets the content type to `text/event-stream` and the transfer encoding to chunked. ::: code http_sse_service.bal :::