-
Notifications
You must be signed in to change notification settings - Fork 5
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
Discussion: Amazing project #6
Comments
Hi, thanks for your comments. I do intend to write a section along the lines of "Why does this exist??". Have been trying to improve the documentation over last few days. When I'm happy with it I'll do some kind of announcement. To answer your question, I too have come from the python ecosystem and over the years I have settled on Why do I prefer to define the spec then generate code, rather than write code then generate the spec? I think these two things are very different ways of working. Using something like Also, an OpenAPI spec is language-agnostic which is very useful in a multi-language environment. In particular, for the frontend, I can use something like swagger-to-ts to generate equivalent typescript types, then I can be confident that my backend and frontend can talk to each other. I have spent so much time over the years debugging API inconsistencies, I want it to stop. In contrast, I find little value in generating an OpenAPI spec from code, as I do not find the spec to be very useful in- and of- itself - and it doesn't free me from doing the tedious bits, namely all the server and client boilerplate. I like to use OpenAPI as a (not that great) IDL, the pretty ui rendering is nice but not really the point. |
Thanks for your prompt reply. |
Interesting. At the moment I think only simple parameters would work (haven't tested anything more complex). The current implementation just does "whatever actix-web does" which I think relies on
I think the parts that are implemented 'work', and the underlying framework (actix-web) is certainly used in production. However there are still lots to do before it supports all the features that would be expected for production use. You can see an incomplete list https://github.com/adwhit/hsr/blob/master/TODO.md. My aim is to implement everything bit-by-bit until it would be possible (at least in principal) to use the framework at my day job. The most conspicuous missing features in this regard are
I would of course be delighted to accept PRs for any features in the TODO, or indeed anything else you think could be improved. Or simply giving it a try and reporting pain points would also be valuable. BTW, this isn't really documented yet but there is a nightly-only feature |
What about error handling. I see Basically, I'm asking how would one do proper error handling with On a side note: |
Hi, thanks for your interest. Error handling: is a slightly tricky one. Versions re: popularity - while this project works fine as it stands, in my view it is not really ready for public use until the above TODO items are completed, so I have made no effort to publicise it yet. When I find the time (hopefully in August) I will add the missing features and polish it a bit, then make some kind of announcement. But in the meantime, please feel free to give it a whirl, the existing API is not likely to change much. |
I sort of always have this question with all libraries in Rust that I've tried: how does this library do error handling? There have been so many ways to do that and will probably continue to be more than one way of doing error handling with Rust, that I wished that more crates had a small section titled "how to handle errors in X crate code". ATM, using crates like anyhow (which strives to stay close to std idiomatic Rust) and the idiomatic (???) 'make your own error type and implement Error' practice seem to me like the best way to do errors with Rust. Seems like it's wanting to converge on that standard but I'm very new to Rust so I might not know what I'm talking about here. What are you opinions on this? Will you consider writing a section like that, on handling errors with |
I'm not the hsr author, but my humble opinion on this as a general topic, which seems to be the consensus, is: anyhow for programs, thiserror for libraries. The thiserror crate facilitates the "Make your own error type" for library code. |
Pretty much agree with @diegopy here. For libraries, create your own precise types with However, for this particular framework, error types will be defined by the user via the spec, so it isn't necessary to include library errors beyond that (at least in principle). re: progress, haven't worked on this recently but it is still on my radar, just need to find a solid uninterrupted week or so to get it polished. |
I kind of switched my focus to async-std, tide, async-h1 and that side of the Rust HTTP async-await server story. Still an amazing project, at least in principle. I do wish it a lot of luck and success and I hope it will be a good fit for most people doing Rust web APIs. |
Hi,
I've been using FastAPI for Python and now that I'm using Rust more I was looking for similar frameworks. I've been playing with hsr and so far seems pretty good. It actually uses the opposite direction than FastAPI. There you annotate your code using Python decorators and type hints and FastAPI fully generates the openapi v3 schema from it, optionally embedding a SwaggerUI in the final runtime to have nice things like "Try it out" to test the API. hsr went for the codegen approach. I'm wondering if you considered both approaches and what where the reasons that made you go for codegen. I'm not sure myself which workflow is better, although I'd like to think that having the code as the single "source of truth" and generating everything from it has some appeal.
Thanks again for this project! Looking forward to hopefully contribute when I start using it.
The text was updated successfully, but these errors were encountered: