Replies: 5 comments 2 replies
-
Please show an example of the problem and the “dynamic approach”. |
Beta Was this translation helpful? Give feedback.
-
Here is the code I copied from crates.io, as you can see, it's taking a dynamic approach for parameter: "sort" and "include_yanked". I know why this won't work. I need to package "sort" and "include_yanked" in a struct, and write: But really, declare a struct for every handler is ugly. Wondering if there is a better way.pub async fn search(app: AppState, req: Parts) -> AppResult<Json> {
|
Beta Was this translation helpful? Give feedback.
-
And in Dotnet, my handler is so simple and straight forward, of course, it's a dynamic language, we are not comparing here. public object GetPhoneLog(int appID, string phone, string code, int minutesago) |
Beta Was this translation helpful? Give feedback.
-
First of all, the dotnet version is my own framework. I made it to search Query first, then Json body. The API can work for GET/POST at the same time. I thought about it, here is my idea, just for discussion:
That being said, this approach has a couple problems:
|
Beta Was this translation helpful? Give feedback.
-
The problem is that the Query parameter is a HashMap and there is no way to query directly for a parameter and get back the string value. It would had been nice if you could extract specific query params by using Query(param_i_need) : Query<String> and directly get the string value I need in the variable. Having to make serializable structs just to extract a query parameter from the request is madness. |
Beta Was this translation helpful? Give feedback.
-
I found I have to create a struct for every handler just because I want to extract a single string parameter from the querystring. I looks very stupid code. anyway to make it better?
I understand that I can use dynamic approach, i.e., extract the data in the handler's func body through hashmap or whatever. But then I lost the rejection feature, and it looks even more stupid.
Any ideas? It's much easier in other dynamic languages like .net. but in RUST, seems that I have a jump the hoop of proc-macro?
Beta Was this translation helpful? Give feedback.
All reactions