-
Notifications
You must be signed in to change notification settings - Fork 29
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
Integration with web frameworks #12
Comments
I created an integration for axum. Still working on tests, docs and CI. But the base source should working, if you want to try it out :) |
Looks good! I have a few questions: Would you be willing to merge it into this repo, so that it can be kept up-to-date more easily? Why is the 2nd type parameter necessary here? Do you think adding an associated type to Do you think it would make sense to create a |
Yes, that would be easier. Let me finish it first
Becase we target the final deserialized value (eg Foo), but we require the type information provided by the extractor (eg Json). It's the same API that I will sleep over the idea tho, maybe there is some way to flip the trait so we can have both the type information and the final target.
It can be done, i just didn't bother (yet). Adding it rn |
I found another API design that is both simpler and easier to use, but of course there is a catch. Instead of creating a new trait for unwrapping tuple structs, we leverage the One alternative would be to impl Serialize/Deserialize on garde and perform validation in situ, but that wouldn't allow usage of Source for this idea is available at the |
I think |
That would allow end users to construct Note: I just realised that Note2: An alternative solution to the whole
Note3: After playing with the proposed solution on note2, it doesn't feel right. Making the constructor private makes the usage of |
Could you please take a look at the |
LGTM! I think the default features should include |
Keeping this open for an integration with |
So I've never used this library, but I have used validator. I had an idea around integrating validation into serde and did some googling to see if anyone has done it, and ended up here. I'm wondering if this might transparently solve your web framework integration. Essentially,
The
The two main issues I see here are:
The major downside here of course is there's no simple way to deserialize your type without validating. Personally I've never wanted to do that but someone might at some point. It also means you end up duplicating every struct in the generated code, which may or may not slow down compilation. I'm happy to work on answering these questions and implementing this, but I wanted to check that my idea makes sense and is something you'd want in garde before doing so. Let me know if I'm crazy or something. |
Unlike in There's the Unvalidated type, which I was hoping would act as a kind of bridge if there is no integration available for your favorite framework. You'd do the equivalent of extracting |
Of course! That makes sense |
We've now got two "proper" integrations: It should be straightforward to use |
It should already be possible to integrate in a straightforward way using the
Unvalidated
type, the only part that's missing is converting the validation errors into some output, but that should be application-specific:The text was updated successfully, but these errors were encountered: