From f6e22d366cc681f0525b988f7bec018fa37f6346 Mon Sep 17 00:00:00 2001 From: Manuel Allenspach Date: Fri, 6 Dec 2024 13:02:58 +0100 Subject: [PATCH] add WebSocket examples --- .github/workflows/test.yml | 1 + README.md | 2 +- .../Collection/Collection.krcol | 3 ++- .../Scripting WebSocket-request-0.txt | 3 +++ .../Scripting WebSocket-request-1.txt | 3 +++ .../Scripting/Scripting WebSocket.js | 14 +++++++++++++ .../Scripting/Scripting WebSocket.krop | 20 ++++++++++++++++++ example-project/WebSocket/Echo-request-0.txt | 3 +++ example-project/WebSocket/Echo-request-1.txt | 1 + example-project/WebSocket/Echo-request-2.txt | 1 + example-project/WebSocket/Echo.krop | 21 +++++++++++++++++++ example-project/directory.krpref | 3 +++ example-project/production.krenv | 1 + example-project/test.krenv | 1 + 14 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 example-project/Kreya features/Scripting/Scripting WebSocket-request-0.txt create mode 100644 example-project/Kreya features/Scripting/Scripting WebSocket-request-1.txt create mode 100644 example-project/Kreya features/Scripting/Scripting WebSocket.js create mode 100644 example-project/Kreya features/Scripting/Scripting WebSocket.krop create mode 100644 example-project/WebSocket/Echo-request-0.txt create mode 100644 example-project/WebSocket/Echo-request-1.txt create mode 100644 example-project/WebSocket/Echo-request-2.txt create mode 100644 example-project/WebSocket/Echo.krop diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 80fab63..6996f0b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,5 +24,6 @@ jobs: - run: kreyac environment set-active Production - run: kreyac operation invoke "REST/Get books.krop" # invoke a single REST operation - run: kreyac operation invoke "gRPC/Say hello (unary call).krop" # invoke a single gRPC operation + - run: kreyac operation invoke "WebSocket/Echo.krop" # invoke a single WebSocket operation - run: kreyac operation invoke "Kreya features/Scripting/**" # invoke all scripting operations - run: kreyac collection invoke "Kreya features/Collection/Collection.krcol" # invoke a collection \ No newline at end of file diff --git a/README.md b/README.md index 07084be..0d052eb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Screenshot of Kreya](https://kreya.app/screenshot.png) -Kreya is a GUI client for gRPC and REST APIs. It makes calling APIs easy! Supported features: +Kreya is a GUI client for gRPC, REST and WebSocket APIs. It makes calling APIs easy! Supported features: - Kreya stores the files locally in JSON format for easy git-syncing (or any other syncing software) - Unary, client-streaming, server-streaming and duplex requests (gRPC) - Supports HTTP/2 and HTTP/3 diff --git a/example-project/Kreya features/Collection/Collection.krcol b/example-project/Kreya features/Collection/Collection.krcol index 6b9fa0e..02a4f07 100644 --- a/example-project/Kreya features/Collection/Collection.krcol +++ b/example-project/Kreya features/Collection/Collection.krcol @@ -3,6 +3,7 @@ "../../gRPC/Say hello (unary call).krop", "../../REST/Create book.krop", "../Scripting/Scripting REST.krop", - "../Scripting/Scripting gRPC.krop" + "../Scripting/Scripting gRPC.krop", + "../Scripting/Scripting WebSocket.krop" ] } \ No newline at end of file diff --git a/example-project/Kreya features/Scripting/Scripting WebSocket-request-0.txt b/example-project/Kreya features/Scripting/Scripting WebSocket-request-0.txt new file mode 100644 index 0000000..a5fd088 --- /dev/null +++ b/example-project/Kreya features/Scripting/Scripting WebSocket-request-0.txt @@ -0,0 +1,3 @@ +{ + "text": "Message 1" +} \ No newline at end of file diff --git a/example-project/Kreya features/Scripting/Scripting WebSocket-request-1.txt b/example-project/Kreya features/Scripting/Scripting WebSocket-request-1.txt new file mode 100644 index 0000000..22f38b0 --- /dev/null +++ b/example-project/Kreya features/Scripting/Scripting WebSocket-request-1.txt @@ -0,0 +1,3 @@ +{ + "text": "Message 2" +} \ No newline at end of file diff --git a/example-project/Kreya features/Scripting/Scripting WebSocket.js b/example-project/Kreya features/Scripting/Scripting WebSocket.js new file mode 100644 index 0000000..95e0f26 --- /dev/null +++ b/example-project/Kreya features/Scripting/Scripting WebSocket.js @@ -0,0 +1,14 @@ +import { expect } from 'chai'; + +let responseCount = 0; + +kreyaWebSocket.onResponseMessage(response => { + responseCount++; + kreya.test('Response content', () => expect(response.content).to.contain(`Message ${responseCount}`)); +}); + +kreyaWebSocket.onCallCompleted(call => { + kreya.trace('The WebSocket call completed.'); + + kreya.test('Status code', () => expect(call.status.code).to.equal(1000)); +}); \ No newline at end of file diff --git a/example-project/Kreya features/Scripting/Scripting WebSocket.krop b/example-project/Kreya features/Scripting/Scripting WebSocket.krop new file mode 100644 index 0000000..348315a --- /dev/null +++ b/example-project/Kreya features/Scripting/Scripting WebSocket.krop @@ -0,0 +1,20 @@ +{ + "details": { + "path": "/ws/echo" + }, + "script": { + "src": "Scripting WebSocket.js" + }, + "requests": [ + { + "location": "Scripting WebSocket-request-0.txt", + "type": "json" + }, + { + "location": "Scripting WebSocket-request-1.txt", + "type": "json" + } + ], + "operationType": "duplexStreaming", + "invokerName": "websocket" +} \ No newline at end of file diff --git a/example-project/WebSocket/Echo-request-0.txt b/example-project/WebSocket/Echo-request-0.txt new file mode 100644 index 0000000..2cceb97 --- /dev/null +++ b/example-project/WebSocket/Echo-request-0.txt @@ -0,0 +1,3 @@ +{ + "text": "My JSON message" +} \ No newline at end of file diff --git a/example-project/WebSocket/Echo-request-1.txt b/example-project/WebSocket/Echo-request-1.txt new file mode 100644 index 0000000..185d7ea --- /dev/null +++ b/example-project/WebSocket/Echo-request-1.txt @@ -0,0 +1 @@ +A raw text message \ No newline at end of file diff --git a/example-project/WebSocket/Echo-request-2.txt b/example-project/WebSocket/Echo-request-2.txt new file mode 100644 index 0000000..5b365be --- /dev/null +++ b/example-project/WebSocket/Echo-request-2.txt @@ -0,0 +1 @@ +U29tZSBiaW5hcnkgY29udGVudA== \ No newline at end of file diff --git a/example-project/WebSocket/Echo.krop b/example-project/WebSocket/Echo.krop new file mode 100644 index 0000000..7862e14 --- /dev/null +++ b/example-project/WebSocket/Echo.krop @@ -0,0 +1,21 @@ +{ + "details": { + "path": "/ws/echo" + }, + "requests": [ + { + "location": "Echo-request-0.txt", + "type": "json" + }, + { + "location": "Echo-request-1.txt", + "type": "text" + }, + { + "location": "Echo-request-2.txt", + "type": "binaryBase64" + } + ], + "operationType": "duplexStreaming", + "invokerName": "websocket" +} \ No newline at end of file diff --git a/example-project/directory.krpref b/example-project/directory.krpref index 86c4d54..ac0a963 100644 --- a/example-project/directory.krpref +++ b/example-project/directory.krpref @@ -20,6 +20,9 @@ } ], "pathParams": [] + }, + "websocket": { + "endpoint": "{{ env.websocket_endpoint }}" } } } diff --git a/example-project/production.krenv b/example-project/production.krenv index f1fc7b4..3117184 100644 --- a/example-project/production.krenv +++ b/example-project/production.krenv @@ -4,6 +4,7 @@ "globalContent": { "grpc_endpoint": "https://example-api.kreya.app:9090", "rest_endpoint": "https://example-api.kreya.app", + "websocket_endpoint": "wss://example-api.kreya.app", "basic_auth_password": "production-password" } } \ No newline at end of file diff --git a/example-project/test.krenv b/example-project/test.krenv index 034051f..8b804d5 100644 --- a/example-project/test.krenv +++ b/example-project/test.krenv @@ -4,6 +4,7 @@ "globalContent": { "grpc_endpoint": "https://example-api.kreya.app:9090", "rest_endpoint": "https://example-api.kreya.app", + "websocket_endpoint": "wss://example-api.kreya.app", "basic_auth_password": "test-password" } } \ No newline at end of file