Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support HTTP/SaaS function trigger #372

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
34af89b
add invoke functionality
KhudaDad414 Jan 23, 2023
cd755e5
add docs
KhudaDad414 Jan 24, 2023
8ad5535
support glee-http-invoke
KhudaDad414 Jan 30, 2023
857602f
tests
KhudaDad414 Jan 31, 2023
1f65d7b
final touches
KhudaDad414 Jan 31, 2023
ebb52be
documentation
KhudaDad414 Jan 31, 2023
d3dbe67
docs
KhudaDad414 Jan 31, 2023
d983439
move fs-extra to dependencies
KhudaDad414 Jan 31, 2023
eaaed67
Merge branch 'master' into support-http
KhudaDad414 Jan 31, 2023
7ece877
update package-lock
KhudaDad414 Jan 31, 2023
c5c49e3
Update docs/functions.md
KhudaDad414 Feb 23, 2023
9e26b22
Update docs/functions.md
KhudaDad414 Feb 23, 2023
d48e61d
Update docs/functions.md
KhudaDad414 Feb 23, 2023
6be5d46
Update docs/functions.md
KhudaDad414 Feb 23, 2023
bdb1f10
refactor
KhudaDad414 Feb 24, 2023
56d4d58
Merge branch 'master' into support-http
KhudaDad414 Feb 24, 2023
e3b195b
cleanup
KhudaDad414 Feb 24, 2023
a328c11
refactor index.d.ts
KhudaDad414 Feb 24, 2023
63e1a8a
recreate package.json
KhudaDad414 Feb 24, 2023
ba7d214
generate functions on the fly
KhudaDad414 Feb 27, 2023
cb34761
Merge branch 'master' into support-http
KhudaDad414 Feb 27, 2023
10e855d
use Got types
KhudaDad414 Feb 28, 2023
3f75998
better docs
KhudaDad414 Feb 28, 2023
13fd336
typo
KhudaDad414 Feb 28, 2023
d1d09b1
final touches
KhudaDad414 Feb 28, 2023
64d850b
ignore body in GET
KhudaDad414 Feb 28, 2023
2ba8d80
remove prettier config
KhudaDad414 Mar 13, 2023
68d254f
Merge remote-tracking branch 'upstream/master' into support-http
KhudaDad414 Aug 11, 2023
b056eb6
Merge branch 'master' into support-http
KhudaDad414 Oct 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ dist
coverage
.vscode
.glee
.next
.next
glee-test
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.md
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 100
}
33 changes: 32 additions & 1 deletion docs/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default async function (event) {
|---|---|---|
|send|array<[OutboundMessage](#anatomy-of-an-outbound-message)>|A list of outbound messages to send when the processing of the inbound event has finished. All clients subscribed to the given channel/topic will receive the message.
|reply|array<[OutboundMessage](#anatomy-of-an-outbound-message)>|A list of outbound messages to send as a reply when the processing of the inbound event has finished. This is useful when the target of your message is the sender of the inbound event. Note, however, that this only works when you're running Glee as a server. For example, using `reply` when receiving a WebSocket message is fine and the reply will exclusively go to the client that sent the message. However, if you're receiving a message from an MQTT broker, `reply` will work exactly the same way as `send` above, and will send the message to all the clients subscribed to the given channel/topic.
|invoke|array<[InvokeRequest](#anatomy-of-an-invoke-message)>|A list of requests for reaching an HTTP/HTTPS endpoint. This is useful when you have a software as a service (SaaS) function and want it to be treated as one of Glee's functions.
KhudaDad414 marked this conversation as resolved.
Show resolved Hide resolved


##### Anatomy of an outbound message
Expand All @@ -48,6 +49,17 @@ export default async function (event) {
|channel|string|The channel/topic you want to send the message to. Defaults to `event.channel`, i.e., the same channel as the received event.
|server|string|The server/broker you want to send the message to. Defaults to `event.serverName`, i.e., the same server as the received event.

##### Anatomy of an invoke message

|Attribute|Type|Description|
|---|---|---|
|url|string|The URL of your HTTP/SaaS end-point.
|headers|object<string,string>|The headers/metadata of the message you want to send.
|method|string|The HTTP method that you want your endpoint to be called with.
|ignoreResponse|boolean|By default, Glee assumes that the response is in JSON format and adheres to the [Functions](#functions) return type structure. If you do not wish for Glee to process the response, you can set the this option to `false`.
KhudaDad414 marked this conversation as resolved.
Show resolved Hide resolved

> NOTE: Glee uses [got](https://github.com/sindresorhus/got) under the hood. Therefore, you have the ability to personalize your request with any options that [got](https://github.com/sindresorhus/got#documentation) supports.
KhudaDad414 marked this conversation as resolved.
Show resolved Hide resolved

## How does Glee know which function it should execute?

Glee reads your `asyncapi.yaml` file and searches for all the `publish` operations containing an `operationId` attribute. The `operationId` serves as a mechanism to bind a given operation to a specific function file. For instance, given the folowing AsyncAPI definition:
Expand All @@ -61,4 +73,23 @@ channels:
...
```

Glee maps the `onHello` operation to the `functions/onHello.js` file.
Glee maps the `onHello` operation to the `functions/onHello.js` file.

## Using FaaS functions as glee functions
KhudaDad414 marked this conversation as resolved.
Show resolved Hide resolved

Glee can treat your FaaS function as its own by setting `operationId` to your function URL and customizing it with the `x-glee-invoke` extension:
KhudaDad414 marked this conversation as resolved.
Show resolved Hide resolved

```yaml
channels:
hello:
publish:
operationId: https://domain.come/path/to/your/function
x-glee-invoke:
method: get
headers:
Content-Type: application/json
ignoreResponse: true # By default, Glee processes the response and raises an error if it does not conform to the format specified by [functions](#functions) return type.
KhudaDad414 marked this conversation as resolved.
Show resolved Hide resolved
...

```
> NOTE: Avoid including authentication details in the asyncapi file. Instead, use the invoke option in [functions](#functions) return to authenticate your call.
Loading