Skip to content

Commit

Permalink
add WebSocket examples
Browse files Browse the repository at this point in the history
  • Loading branch information
CommonGuy committed Jan 16, 2025
1 parent 4c4fe89 commit b0395fb
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion example-project/Kreya features/Collection/Collection.krcol
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"text": "Message 1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"text": "Message 2"
}
14 changes: 14 additions & 0 deletions example-project/Kreya features/Scripting/Scripting WebSocket.js
Original file line number Diff line number Diff line change
@@ -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));
});
20 changes: 20 additions & 0 deletions example-project/Kreya features/Scripting/Scripting WebSocket.krop
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 3 additions & 0 deletions example-project/WebSocket/Echo-request-0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"text": "My JSON message"
}
1 change: 1 addition & 0 deletions example-project/WebSocket/Echo-request-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A raw text message
1 change: 1 addition & 0 deletions example-project/WebSocket/Echo-request-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
U29tZSBiaW5hcnkgY29udGVudA==
21 changes: 21 additions & 0 deletions example-project/WebSocket/Echo.krop
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 3 additions & 0 deletions example-project/directory.krpref
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
}
],
"pathParams": []
},
"websocket": {
"endpoint": "{{ env.websocket_endpoint }}"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions example-project/production.krenv
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
1 change: 1 addition & 0 deletions example-project/test.krenv
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit b0395fb

Please sign in to comment.