Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch backend from pure Websocket API to a REST API #233

Open
1 of 3 tasks
FSMaxB opened this issue Sep 24, 2021 · 7 comments
Open
1 of 3 tasks

Switch backend from pure Websocket API to a REST API #233

FSMaxB opened this issue Sep 24, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@FSMaxB
Copy link
Member

FSMaxB commented Sep 24, 2021

Websockets are great for one-off notifications but not for request/response style communication.

Currently most of the API is actually following the request/response pattern which means that the Frontend needs to reimplement it on top of Websockets which involves request ID tracking and timeout handling. It's a much better idea to just use HTTP for that, since it's designed to follow the request/response model.

The initial version of the REST API should:

  • Model the same functionality as the current websocket API. Including a mechanism for protecting against outdated resource updates (what the MediumVersion currently provides)
  • Be documented via Open API, if possible automatically generated from the backend code.
  • Not replace Websockets for situations where the server contacts the client.

We're still evaluating if we stay with Gotham or switch to a different web framework for this. Web frameworks looked at:

  • rocket
  • gotham
    • We're already using it for the websocket API (although with manual websocket implementation)
    • Already familiar with the codebase
    • Supports OpenAPI via gotham_restful although this is kind of tacked on
    • No builtin way to do REST APIs, we would need to rely on gotham_restful mentioned above
  • axum
  • rweb
    • Builtin support for Open API
    • Builtin support for websockets
    • Based on warp, which we switched away from in the past because the compile times were unbearable (but which was awesome apart from that)
@FSMaxB FSMaxB added the enhancement New feature or request label Sep 24, 2021
@FSMaxB
Copy link
Member Author

FSMaxB commented Sep 27, 2021

As of #241 we've fully switched to rweb!

@simonsan
Copy link

As of #241 we've fully switched to rweb!

How are your experiences for now with rweb?

@FSMaxB
Copy link
Member Author

FSMaxB commented Jan 14, 2022

How are your experiences for now with rweb?

@simonsan Great, until you try multiple #[data] parameters or other stuff that one would want to do. So switching to axum after all. Might have to do OpenAPI manually or implement support for it ourselves if noone else picks up the work on it.

@simonsan
Copy link

How are your experiences for now with rweb?

@simonsan Great, until you try multiple #[data] parameters or other stuff that one would want to do. So switching to axum after all. Might have to do OpenAPI manually or implement support for it ourselves if noone else picks up the work on it.

Interesting, warp directly would not be an option? If so, why have you decided against it?

@FSMaxB
Copy link
Member Author

FSMaxB commented Jan 14, 2022

Interesting, warp directly would not be an option? If so, why have you decided against it?

We've initially been using warp actually (before gotham). The ergonomics of the Filter trait aren't too great and you can't even make a custom implementation (or if so, I haven't yet found out how). Also warp doesn't have the concept of an API, just Filters, so given that and how it works in general, I'm not sure how one could automatically create an OpenAPI API description from it without essentially writing your own Web-Framework on top of it.

Apart from the list above we also considered actix-web, but given some bad experience in the past, we decided against it (which might not have been a completely rational decision as from the things I know now, it would probably have been a great contender). But given that my current employer was using actix-web already and just recently migrated from it to axum, axum looks like an even better choice than previously because I can piggy back on my experience from work. Also the API is quite nice in terms of both being simple and powerful at the same time.

But if you want to work with generated OpenAPI descriptions right now, taking another look at actix-web and paperclip might not be such a bad idea.

@simonsan
Copy link

Funnily I'm working with warp currently, more because I tried actix-web and it didn't work well with reqwest due to some incompatibility in the async runtime. So I was stuck with warp, because I wanted to stick with reqwest due to redirects, wasm and other things. So I thought warp and reqwest might be a good combination. I will try axum for sure as well for a smaller project and take a look at the ergonomics. Thank you for you review!

@FSMaxB
Copy link
Member Author

FSMaxB commented Dec 4, 2022

axum with automatically generated OpenAPI description is ready, see #777

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants