s3rius / FastAPI-template

Feature rich robust FastAPI template.
MIT License
1.83k stars 161 forks source link

Add WebSocket Examples #152

Open DeanNeaht opened 1 year ago

DeanNeaht commented 1 year ago

Hello,

I noticed that the current version of the FastAPI-Template project does not include examples of using WebSockets with FastAPI. I think adding these examples would be helpful for developers.

It's worth noting that DI for WebSockets is different from DI for HTTP routes and testing.

I want to suggest adding examples of using WebSockets to the project.

I'm willing to help with this and can provide code examples as needed.

s3rius commented 1 year ago

Hi, and thanks for trying to make fastapi-template even better.

That's a good idea. I'll look into it this evening. Can you provide some ideas what should be done in this example? Simple echo server, or maybe something more mature?

DeanNeaht commented 1 year ago

I believe that a simple echo server and an example with a dummy model would be good examples to include in the project.

In the dummy model example, we could have clients subscribe to changes in the model, and have the server broadcast updates to all connected clients. This would demonstrate how WebSockets can be used to create real-time, collaborative applications.

s3rius commented 1 year ago

I guess that subscribing for a model updates is a very big example. Maybe small message broadcasting would be enough? Like if someone writes a message, it sends to all connected people?

But I'm not sure that this is what is really needed, since these examples are exist here in fastapi docs.

s3rius commented 1 year ago

I don't really want to create a really big example, since it would be hard to support. But what I really like is the idea to show the example how to test websockets. So maybe echo or broadcast is enough.

DeanNeaht commented 1 year ago

I agree that subscribing to model updates may be a big example, and a simple echo or broadcast may be sufficient.

However, I would still like to propose including an example that demonstrates the proper use of DI with WebSockets. Because, there are issues with DI in FastAPI that are not well-documented, and I believe that including an example would be very helpful for developers who are new to FastAPI or WebSockets.

In fact, I recently came across a discussion on GitHub where this issue was raised. Here is the link. As you can see, there are developers who have experienced problems with DI in FastAPI and would benefit from a clear example.

eggb4by commented 1 year ago

I agree that subscribing to model updates may be a big example, and a simple echo or broadcast may be sufficient.

However, I would still like to propose including an example that demonstrates the proper use of DI with WebSockets. Because, there are issues with DI in FastAPI that are not well-documented, and I believe that including an example would be very helpful for developers who are new to FastAPI or WebSockets.

In fact, I recently came across a discussion on GitHub where this issue was raised. Here is the link. As you can see, there are developers who have experienced problems with DI in FastAPI and would benefit from a clear example.

I have same issue now....