From d49bc4c4749621981fb7e12c40c4be4f4506c31e Mon Sep 17 00:00:00 2001 From: Alexis DRAI Date: Sat, 11 Feb 2023 12:27:11 +0100 Subject: [PATCH] :gift: :memo: --- README.md | 21 +++ docs/Cat Café.postman_collection.json | 229 +++++++++++++++++++++++++ 2 files changed, 250 insertions(+) create mode 100644 docs/Cat Café.postman_collection.json diff --git a/README.md b/README.md index dfde72f..f46c985 100644 --- a/README.md +++ b/README.md @@ -9,19 +9,23 @@ * [WebSocket](#websocket) * [API type choices](#api-type-choices) * [API Gateway](#api-gateway) +* [Testing the app](#testing-the-app) ## Global architecture +--- ### Concept This application attempts to modelize a cat café, with cafés (called "bars" here), cats, and customers. +--- ### REST API Those three entities can be persisted via a REST API. They can also be updated, queried, and removed. We used an ASP .NET Web API, with a Swagger configuration to visualize the interface. +--- ### WebSocket A WebSocket was set up to notify clients (who subscribe to it) whenever a Cat is `POST`ed. @@ -40,6 +44,7 @@ new WebSocket("wss://localhost:5003/gateway/ws").onmessage = function (event) { - `"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 type choices #### REST API @@ -61,8 +66,11 @@ Since the connection is opened once and closed once, we avoid any performance lo and closing a connection for each request-response cycle. Similarly, a server that uses a websocket can reduce its load, because it is now pushing updates directly instead of being polled regularly by many clients. +--- ### API Gateway +#### How to launch both projects + An [Ocelot](https://ocelot.readthedocs.io/en/latest/) API Gateway manages the whole system. It can be started using Visual Studio if you first right-click the cat-cafe.sln Solution, and go to Properties. @@ -155,6 +163,19 @@ The gateway uses rate limiting to make sure that clients cannot send an all-incl } } ... ``` +--- +## Testing the app + +0. Prepare to use Postman +1. Start both the `cat_cafe` and `ApiGateway` projects (you may refer to [this procedure](#how-to-launch-both-projects)). Two browser windows will open, which you will not need to use much. +2. Use whichever browser window to open a WebSocket, so that you will get notifications (you may refer to [that procedure](#websocket)) +3. In Postman, inside a workspace, click the `Import` button in the top left corner. Then click `Choose files` and find the collection to import in `docs/Cat Café.postman_collection.json`, in this repo. Follow the procedure to save it. +4. Keep an eye on the browser window you used to open a WebSocket, and execute the requests in this imported collection. When using `POST`, you should get an alert in the browser window. + +Notice that the REST API and the WebSocket are accessed through our API Gateway. + +In a real-life scenario, we could use IP-blocking or firewalls to ensure that port 7229 can only be accessed by the app itself and the gateway. + --- ## To contribute (workflow) diff --git a/docs/Cat Café.postman_collection.json b/docs/Cat Café.postman_collection.json new file mode 100644 index 0000000..ab88daa --- /dev/null +++ b/docs/Cat Café.postman_collection.json @@ -0,0 +1,229 @@ +{ + "info": { + "_postman_id": "4448c1b2-03b7-4b34-9d5b-ee364ff17986", + "name": "Cat Café", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "25802734" + }, + "item": [ + { + "name": "Create cat 1", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"name\": \"Versailles\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "https://localhost:5003/gateway/cats", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5003", + "path": [ + "gateway", + "cats" + ] + } + }, + "response": [] + }, + { + "name": "Create cat 2", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"name\": \"Llanfair­pwll­gwyn­gyll­go­gery­chwyrn­drobwll­llan­tysilio­gogo­goch\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "https://localhost:5003/gateway/cats", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5003", + "path": [ + "gateway", + "cats" + ] + } + }, + "response": [] + }, + { + "name": "Create cat 3", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"name\": \"London\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "https://localhost:5003/gateway/cats", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5003", + "path": [ + "gateway", + "cats" + ] + } + }, + "response": [] + }, + { + "name": "Read all cats", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "https://localhost:5003/gateway/cats", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5003", + "path": [ + "gateway", + "cats" + ] + } + }, + "response": [] + }, + { + "name": "Read cat 2", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "https://localhost:5003/gateway/cats/2", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5003", + "path": [ + "gateway", + "cats", + "2" + ] + } + }, + "response": [] + }, + { + "name": "Update cat 3", + "request": { + "method": "PUT", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"id\": 3,\r\n \"name\": \"Camden Town\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "https://localhost:5003/gateway/cats/3", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5003", + "path": [ + "gateway", + "cats", + "3" + ] + } + }, + "response": [] + }, + { + "name": "Read all cats", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "https://localhost:5003/gateway/cats", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5003", + "path": [ + "gateway", + "cats" + ] + } + }, + "response": [] + }, + { + "name": "Delete cat 1", + "request": { + "method": "DELETE", + "header": [], + "url": { + "raw": "https://localhost:5003/gateway/cats/1", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5003", + "path": [ + "gateway", + "cats", + "1" + ] + } + }, + "response": [] + }, + { + "name": "Read all cats", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "https://localhost:5003/gateway/cats", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5003", + "path": [ + "gateway", + "cats" + ] + } + }, + "response": [] + } + ] +} \ No newline at end of file