You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 9, 2024. It is now read-only.
Custom event subscriptions are asynchronous. There is a special `http` event type for creating synchronous
230
-
subscriptions. `http` event is an HTTP request received to specified path and for specified HTTP method. There can be
231
-
only one `http` subscription for the same `method` and `path` pair.
252
+
#### Example: Subscribe to an `http.request` Event
232
253
233
-
#### Example: Subscribe to an "http" Event
254
+
Not all data are events that's why Event Gateway has a special, built-in [`http.request` event type](./docs/api.md#http-request-event) that enables subscribing to
255
+
raw HTTP requests.
234
256
235
257
<detailsopen>
236
258
<summary>curl example</summary>
@@ -285,6 +307,16 @@ Technically speaking Space is a mandatory field ("default" by default) on Functi
285
307
to provide during function registration or subscription creation. Space is a first class concept in Config API. Config
286
308
API can register function in specific space or list all functions or subscriptions from a space.
287
309
310
+
## CloudEvents Support
311
+
312
+
Event Gateway has the first-class support for [CloudEvents](https://cloudevents.io/). It means few things.
313
+
314
+
First of all, if the event emitted to the Event Gateway is in CloudEvents format, the Event Gateway is able to recognize it and trigger proper subscriptions based on event type specified in the event. Event Gateway supports both Structured Content and Binary Content modes described in [HTTP Transport Binding spec](https://github.com/cloudevents/spec/blob/master/http-transport-binding.md).
315
+
316
+
Secondly, there is a special, built-in [HTTP Request Event](./docs/api.md#http-request-event) type allowing reacting to raw HTTP requests that are not formatted according to CloudEvents spec. This event type can be especially helpful for building REST APIs.
@@ -6,18 +6,39 @@ This document contains the API documentation for both Events and Configuration A
6
6
## Contents
7
7
8
8
1.[Events API](#events-api)
9
+
1.[Event Definition](#event-definition)
10
+
1.[How To Emit an Event](#how-to-emit-an-event)
11
+
1.[HTTP Request Event](#http-request-event)
12
+
1.[Legacy Mode](#legacy-mode)
9
13
1.[Configuration API](#configuration-api)
14
+
1.[Event Types](#event-types)
15
+
1.[Register Event Type](#register-event-type)
16
+
1.[Update Event Type](#update-event-type)
17
+
1.[Delete Event Type](#delete-event-type)
18
+
1.[Get Event Types](#get-event-types)
19
+
1.[Get Event Type](#get-event-type)
20
+
1.[Functions](#functions)
21
+
1.[Register Function](#register-function)
22
+
1.[Update Function](#update-function)
23
+
1.[Delete Function](#delete-function)
24
+
1.[Get Functions](#get-functions)
25
+
1.[Get Function](#get-function)
26
+
1.[Subscriptions](#subscriptions)
27
+
1.[Create Subscription](#create-subscription)
28
+
1.[Update Subscription](#update-subscription)
29
+
1.[Delete Subscription](#delete-subscription)
30
+
1.[Get Subscriptions](#get-subscriptions)
31
+
1.[Get Subscription](#get-subscription)
32
+
1.[Prometheus Metrics](#prometheus-metrics)
33
+
1.[Status](#status)
10
34
11
35
## Events API
12
36
13
-
[OpenAPI spec](./openapi/openapi-events-api.yaml)
14
-
15
-
The Event Gateway exposes an API for emitting events. Events API can be used for emitting custom event, HTTP events and
16
-
for invoking function. By default Events API runs on `:4000` port.
37
+
The Event Gateway exposes an API for emitting events. By default Events API runs on `:4000` port.
17
38
18
39
### Event Definition
19
40
20
-
All data that passes through the Event Gateway is formatted as a CloudEvent, based on [CloudEvents v0.1 schema](https://github.com/cloudevents/spec/blob/master/spec.md):
41
+
All data that passes through the Event Gateway is formatted as a CloudEvent, based on [CloudEvents v0.1 schema](https://github.com/cloudevents/spec/blob/master/spec.md).
21
42
22
43
Example:
23
44
@@ -33,19 +54,29 @@ Example:
33
54
}
34
55
```
35
56
36
-
When an event occurs, all subscribers are called with the event in above schema as its argument.
57
+
### How To Emit an Event
37
58
38
-
#### Event Data Type
59
+
Creating a subscription requires `path` (default: `/`), `method` (default: `POST`) and `eventType`. `path` indicates path under which you can send the event.
39
60
40
-
The MIME type of the data block can be specified using the `Content-Type` header (by default it's
41
-
`application/octet-stream`). This allows the event gateway to understand how to deserialize the data block if it needs
42
-
to. In case of `application/json` type the event gateway passes JSON payload to the target functions. In any other case
43
-
the data block is base64 encoded.
61
+
**Endpoint**
62
+
63
+
`POST <Events API URL>/<Subscription Path>`
64
+
65
+
**Request**
66
+
67
+
CloudEvents payload
44
68
45
-
#### HTTP Request Event
69
+
**Response**
70
+
71
+
Status code:
72
+
73
+
*`202 Accepted` - this status code is returned if there is no [`sync` subscription](./subscription-types.md) defined. Otherwise, status code is controlled by function synchronously subscribed on this endpoint.
74
+
75
+
### HTTP Request Event
46
76
47
-
`http.request` event is a built-in type of event occurring for HTTP requests on paths defined in HTTP subscriptions. The
48
-
`data` field of an `http.request` event has the following structure:
77
+
Not all data are events that's why Event Gateway has a special, built-in `http.request` event type that enables subscribing to
78
+
raw HTTP requests. It's especially helpful for building REST APIs or supporting legacy payloads. `http.request` event is a
79
+
CloudEvent created by Event Gateway where `data` field has the following structure:
49
80
50
81
*`path` - `string` - request path
51
82
*`method` - `string` - request method
@@ -55,84 +86,141 @@ the data block is base64 encoded.
55
86
*`params` - `object` - matched path parameters
56
87
*`body` - depends on `Content-Type` header - request payload
57
88
58
-
### Emit a Custom Event
89
+
### Legacy Mode
59
90
60
-
Creating a subscription requires `path` property (by default it's "/"). `path` indicates path under which you can push an
61
-
event.
91
+
*Legacy mode is deprecated and will be removed in upcoming releases.*
62
92
63
-
**Endpoint**
93
+
In legacy mode, Event Gateway is able to recognize event type based on `Event` header. If the event is not formatted according to CloudEvents specification Event Gateway looks for this header and creates CloudEvent internally. In this case, whole request body is put into `data` field.
64
94
65
-
`POST <Events API URL>/<Subscription Path>`
95
+
#### Event Data Type
96
+
97
+
The MIME type of the data block can be specified using the `Content-Type` header (by default it's
98
+
`application/octet-stream`). This allows the Event Gateway to understand how to deserialize the data block if it needs
99
+
to. In case of `application/json` type the Event Gateway passes JSON payload to the target functions. In any other case
100
+
the data block is base64 encoded.
101
+
102
+
## Configuration API
103
+
104
+
[OpenAPI spec](./openapi/openapi-config-api.yaml)
66
105
67
-
**Request Headers**
106
+
The Event Gateway exposes a RESTful JSON configuration API. By default Configuration API runs on `:4001` port.
107
+
108
+
### Event Types
109
+
110
+
#### Register Event Type
111
+
112
+
**Endpoint**
68
113
69
-
*`Event` - `string` - required, event name
70
-
*`Content-Type` - `MIME type string` - payload type
114
+
`POST <Configuration API URL>/v1/spaces/<space>/eventtypes`
71
115
72
116
**Request**
73
117
74
-
arbitrary payload, subscribed function receives an event in Event schema
118
+
JSON object:
119
+
120
+
*`name` - `string` - required, event type name
121
+
*`authorizerId` - `string` - authorizer function ID
75
122
76
123
**Response**
77
124
78
125
Status code:
79
126
80
-
*`202 Accepted`
127
+
*`201 Created` on success
128
+
*`400 Bad Request` on validation error
129
+
130
+
JSON object:
81
131
82
-
### Emit an HTTP Event
132
+
*`space` - `string` - space name
133
+
*`name` - `string` - event type name
134
+
*`authorizerId` - `string` - authorizer function ID
83
135
84
-
Creating HTTP subscription requires `method` and `path` properties. Those properties are used to listen for HTTP events.
136
+
---
137
+
138
+
#### Update Event Type
85
139
86
140
**Endpoint**
87
141
88
-
`<method> <Events API URL>/<path>`
142
+
`PUT <Configuration API URL>/v1/spaces/<space>/eventtypes/<event type name>`
89
143
90
144
**Request**
91
145
92
-
arbitrary payload, subscribed function receives an event in [HTTP Event](#http-event) schema.
146
+
JSON object:
147
+
148
+
*`authorizerId` - `string` - authorizer function ID
93
149
94
150
**Response**
95
151
96
-
HTTP subscription response depends on [response object](#respond-to-an-http-request-event) returned by the backing function. In case of failure during function invocation following error response are possible:
152
+
Status code:
153
+
154
+
*`200 OK` on success
155
+
*`400 Bad Request` on validation error or if the authorizer function doesn't exist
156
+
*`404 Not Found` if event type doesn't exist
157
+
158
+
JSON object:
97
159
98
-
*`404 Not Found` if there is no backing function registered for requested HTTP endpoint
99
-
*`500 Internal Server Error` if the function invocation failed or the backing function didn't return [HTTP response object](#respond-to-an-http-request-event)
160
+
*`space` - `string` - space name
161
+
*`name` - `string` - event type name
162
+
*`authorizerId` - `string` - authorizer function ID
100
163
101
-
#### Path parameters
164
+
---
102
165
103
-
The Event Gateway allows creating HTTP subscription with parameterized paths. Every path segment prefixed with `:` is
104
-
treated as a parameter, e.g. `/users/:id`.
166
+
#### Delete Event Type
105
167
106
-
The Event Gateway prevents from creating subscriptions in following conflicting situations:
168
+
Delete event type. This operation fails if there is at least one subscription using the event type.
169
+
170
+
**Endpoint**
107
171
108
-
* registering static path when there is parameterized path registered already (`/users/:id` vs. `/users/foo`)
109
-
* registering parameterized path with different parameter name (`/users/:id` vs. `/users/:name`)
172
+
`DELETE <Configuration API URL>/v1/spaces/<space>/eventtypes/<event type name>`
110
173
111
-
Key and value of matched parameters are passed to a function in an HTTP Event under `params` field.
174
+
**Response**
112
175
113
-
##### Wildcard parameters
176
+
Status code:
114
177
115
-
Special type of path parameter is wildcard parameter. It's a path segment prefixed with `*`. Wildcard parameter can only
116
-
be specified at the end of the path and will match every character till the end of the path. For examples
117
-
parameter `/users/*userpath` for request path `/users/group1/user1` will match `group1/user1` as a `userpath` parameter.
178
+
*`204 No Content` on success
179
+
*`400 Bad Request` if there are subscriptions using the event type
180
+
*`404 Not Found` if event type doesn't exist
118
181
119
-
#### Respond to an HTTP Request Event
182
+
---
120
183
121
-
To respond to an HTTP event a function needs to return object with following fields:
184
+
#### Get Event Types
122
185
123
-
*`statusCode` - `int` - response status code, default: 200
124
-
*`headers` - `object` - response headers
125
-
*`body` - `string` - required, response body
186
+
**Endpoint**
126
187
127
-
Currently, the event gateway supports only string responses.
188
+
`GET <Configuration API URL>/v1/spaces/<space>/eventtypes`
128
189
129
-
## Configuration API
190
+
**Response**
130
191
131
-
[OpenAPI spec](./openapi/openapi-config-api.yaml)
192
+
Status code:
193
+
194
+
*`200 OK` on success
195
+
196
+
JSON object:
197
+
198
+
*`eventTypes` - `array` of `object` - event types:
199
+
*`space` - `string` - space name
200
+
*`name` - `string` - event type name
201
+
*`authorizerId` - `string` - authorizer function ID
202
+
203
+
#### Get Event Type
204
+
205
+
**Endpoint**
206
+
207
+
`GET <Configuration API URL>/v1/spaces/<space>/eventtypes/<event type name>`
208
+
209
+
**Response**
210
+
211
+
Status code:
212
+
213
+
*`200 OK` on success
214
+
*`404 Not Found` if event type doesn't exist
215
+
216
+
JSON object:
217
+
218
+
*`space` - `string` - space name
219
+
*`name` - `string` - event type name
220
+
*`authorizerId` - `string` - authorizer function ID
132
221
133
-
The Event Gateway exposes a RESTful JSON configuration API. By default Configuration API runs on `:4001` port.
0 commit comments