Skip to content

Commit 2d0c0e2

Browse files
docs: add docs for endpoints
1 parent 535ee63 commit 2d0c0e2

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

DOCS.md

+26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
11
# Session 4 API Documentation
22

33
This is the API documentation for the AEC 2024 Skill 08 Session 4 API.
4+
5+
## Events
6+
7+
The API provides an endpoint to subscribe to events.
8+
9+
### Subscribe to an Event
10+
11+
This endpoint uses HTTP Long Polling, meaning the connection will remain open until an event is available. Clients should make a request to this endpoint and wait for a response. Once a response is received, the client should immediately make another request to continue receiving events.
12+
13+
!!! note
14+
15+
For the initial request, it is possible to pass the query parameter `wait=false` to get the current event immediately.
16+
17+
```
18+
GET /events/:id/subscribe
19+
```
20+
21+
Example Response
22+
23+
```json
24+
{
25+
"action": {
26+
"type": "flashlight"
27+
}
28+
}
29+
```

src/events/events.controller.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ export class EventsController {
2121
poll(
2222
@Res() res: Response,
2323
@Param('id') id: string,
24-
@Query('isInitialRequest') isInitialRequestParam: string,
24+
@Query('wait') waitParam: string,
2525
) {
2626
const event = events.find((e) => e.name === id);
2727
if (!event) throw new NotFoundException('Event not found');
2828

29-
const isInitialRequest = isInitialRequestParam === 'true';
30-
if (isInitialRequest) {
29+
const wait = waitParam === 'false';
30+
if (wait) {
3131
return res.json(this.eventsService.getCurrentAction(event.name));
3232
}
3333

0 commit comments

Comments
 (0)