-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com>
- Loading branch information
1 parent
f0dffb9
commit 3a5cc90
Showing
5 changed files
with
143 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# HTTP | ||
|
||
You connect to a gateway via standard HTTP 1.1. While connecting to a gateway, the path holds pointers to the type of gateway, the tenant, the application id, and the gateway name. | ||
|
||
The URL structure is http://\<control-plane-domain>:\<api-gateway-port>/api/gateways/\<gateway-type>/\<tenant-name>/\<application-id>/\<gateway-id>. | ||
|
||
Authentication (`credentials,test-credentials`), options (`option:`) and parameters (`param:`) are expected to be in the query string. HTTP headers are ignored by the API Gateway service. | ||
|
||
|
||
## Produce messages | ||
|
||
To produce messages via HTTP, configure a `produce` gateway: | ||
```yaml | ||
|
||
gateways: | ||
- id: "user-input" | ||
type: produce | ||
topic: "questions-topic" | ||
parameters: | ||
- sessionId | ||
``` | ||
Once a gateway is configured, you can use whatever HTTP client you prefer to connect. This is an example with Curl: | ||
```bash | ||
curl -X POST --body '{"value": "hello"}' "http://localhost:8091/api/gateways/produce/my-tenant/my-app/user-input?param:sessionId=12543yusi1" | ||
``` | ||
You can also use the LangStream CLI: | ||
```bash | ||
langstream gateway produce my-app user-input --protocol http -v '{"value": "hello"}' -p sessionId=12543yusi1 | ||
``` | ||
## Produce messages and wait for a message | ||
To produce messages via HTTP and wait for a message, configure a `service` gateway: | ||
```yaml | ||
gateways: | ||
- id: "user-input-await" | ||
type: service | ||
parameters: | ||
- sessionId | ||
service-options: | ||
input-topic: inputs | ||
output-topic: results | ||
``` | ||
|
||
Once a gateway is configured, you can use whatever HTTP client you prefer to connect. This is an example with Curl: | ||
|
||
```bash | ||
curl -X POST --body '{"value": "hello"}' "http://localhost:8091/api/gateways/service/my-tenant/my-app/user-input-await" | ||
``` | ||
|
||
The timeout of the wait is the TCP timeout of the connection, which is usually 30 seconds (may vary depending on the http client). | ||
|
||
## Proxy service agent requests | ||
|
||
To proxy requests to a specific `service` agent via HTTP, configure a `service` gateway: | ||
|
||
```yaml | ||
gateways: | ||
- id: "my-service" | ||
type: service | ||
parameters: | ||
- sessionId | ||
service-options: | ||
agent-id: my-service-agent | ||
``` | ||
|
||
A service agent might look like this in the pipeline configuration: | ||
```yaml | ||
pipeline: | ||
- name: "Start my service" | ||
id: my-service-agent | ||
type: "python-service" | ||
configuration: | ||
className: example.ChatBotService | ||
``` | ||
|
||
|
||
Once a gateway is configured, you can use whatever HTTP client you prefer to connect. This is an example with Curl: | ||
|
||
```bash | ||
curl -X POST \ | ||
--body '{"value": "hello"}' \ | ||
--H 'Authorization: Bearer XXX' \ | ||
"http://localhost:8091/api/gateways/service/my-tenant/my-app/my-service/the/custom/path?service-param-1=yes" | ||
``` | ||
|
||
The final part of the URL, query string, HTTP method, and headers will be sent to the service agent. | ||
|
||
|
||
In the above case, the agent service will receive an equivalent request of: | ||
|
||
``` | ||
curl -X POST \ | ||
--body '{"value": "hello"}' \ | ||
--H 'Authorization: Bearer XXX' \ | ||
"http://localhost:8000/the/custom/path?service-param-1=yes" | ||
``` | ||
|
||
|
||
The `credentials`, `test-credentials`, `option:xx`, `param:xx` are stripped out from the routed requests. | ||
If the gateway has authentication enabled, it will be performed as for other gateways. | ||
|
||
POST, GET, DELETE and PUT are all supported. | ||
|
||
Leveraging the API gateway to expose your service solves authentication, HTTPS, high-availability, and scalability out of the box. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters