This application attempts to modelize a cat café, with cafés (called "bars" here), cats, and customers. The cats can go "meow".
This application attempts to modelize a cat café, with cafés (called "bars" here), cats, and customers.
### API REST
### API REST
@ -18,8 +18,21 @@ We used an ASP .NET Web API, with a Swagger configuration to visualize the inter
### WebSocket
### WebSocket
...
A websocket was set up to notify clients (who subscribe to it) whenever a Cat is `POST`ed.
Clients need to subscribe by typing the following code in the console of their browser, in developer mode :
```js
new WebSocket("wss://localhost:5003/gateway/ws").onmessage = function (event) {
if (event.data === "entity-created") {
alert("A new entity was created!");
}
};
```
*Note*:
- while the app uses port `7229` in our default config, **you should use port `5003` anyway** to subscribe to our WebSocket through our *API Gateway*
- `"entity-created"` is a hard-coded event ID and should not be changed.
- you are free to change the content of the `Alert` itself, of course
### API Gateway
### API Gateway
An [Ocelot](https://ocelot.readthedocs.io/en/latest/) API Gateway manages the whole system.
An [Ocelot](https://ocelot.readthedocs.io/en/latest/) API Gateway manages the whole system.
@ -56,10 +69,19 @@ The Gateway routes offer access to the REST API in a similar way as the REST API
| REST(old) | Gateway(current) |
| REST(old) | Gateway(current) |
|--|--|
|--|--|
| `.../7229/api/...` | `.../5003/gateway/...` |
| `GET` on `https://localhost/7229/api/cats` | `GET` on `https://localhost/5003/gateway/cats` |
| `GET` on `https://localhost/7229/api/cats` | `GET` on `https://localhost/5003/gateway/cats` |
| `POST` on `https://localhost/7229/api/bars/{id}` | `GET` on `https://localhost/5003/gateway/bars/{id}` |
| `POST` on `https://localhost/7229/api/bars/{id}` | `GET` on `https://localhost/5003/gateway/bars/{id}` |
...and for the websocket:
- old :
```js
new WebSocket("wss://localhost:7229/ws").onmessage = function (event) {...};
```
- new :
```js
new WebSocket("wss://localhost:5003/gateway/ws").onmessage = function (event) {...};
```
#### Caching
#### Caching
The gateway uses caching to ensure that the entire list of customers is only queried from the database once every 10 seconds. The rest of the time, clients sending `GET`-all requests get served the contents of a cache.
The gateway uses caching to ensure that the entire list of customers is only queried from the database once every 10 seconds. The rest of the time, clients sending `GET`-all requests get served the contents of a cache.