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
Better URL Pattern Matching #47
Comments
+1 |
Yes, this is a bit of a headache with the current configuration approach. For right now, you can use the configuration flavor that takes an arbitrary predicate to make more fine-grained matches. For example (just a sketch, untested): api.configureTransformer({ $0.path?.rangeOfString("/products/\\d+$", options: .RegularExpressionSearch) != nil }) { … }
api.configureTransformer("/products/filters") { … }
api.configureTransformer("/products/*/market") { … } (Ugh, that Foundation regex API. Hmm, Siesta could — should — make The most obvious better solution is a “first match wins” policy in the manner of a routing engine, but that doesn’t work because configuration blocks aren’t mutually exclusive: you may want to have several independent config passes match the same resource. The “no more transforming, we’re done” approach would solve this immediate problem, but feels like it won’t generalize well, and will lead to more special cases. A slightly more generic version of it I’ve considered would allow you to give configuration blocks a key, where a new config block replaces one with the same key if it exists: api.configureTransformer("/products/*", inSlot: .ModelTransform) { … }
api.configureTransformer("/products/filters", inSlot: .ModelTransform) { … } // replaces first one
api.configureTransformer("/products/**", inSlot: .FastTimeout) { … } // does not override first one This would help #32 play out right. The implementation details get messy, though, and I’m not sure it’s all that easy to understand. Another approach would be to create configuration groups, within which the first match wins: api.configurationGroup { group in
group.configureTransformer("/products/filters") { … }
group.configureTransformer("/products/*") { … }
} Again, though, messy details and maybe hard to follow. |
I'm running in a simpler problem that maybe has already a solution that I can't see. I have two endpoints:
Configuring them like:
Siesta catches the latter also on "products/" call (and it's correct, I think). So the only solution that came to my mind was:
That really isn't so good as something like: * authorization is configured in this way
|
Hi, first great work ; this lib is really changing the way we do networks in iOS apps ! Any updates on this issue ? |
This should now work if you pull the bleeding edge from master: api.configureTransformer("/products/*") { returns Product }
api.configureTransformer("/products/filters") { returns Filter } // overrides previous; order matters!
api.configureTransformer("/products/*/market") { returns Market } // not matched by either of previous 2 rules |
I have setup a handful of routes such as:
When the '/products/filters' resource is loaded it handles it then passes 'Filter' objects into the 'products/*' handler which expects a JSON (SwiftyJSON) object. So of course the 'WrongTypeInTranformerPipeline' error pops up.
It would be nice to either allow a ResponseTransformer to say "no more transforming, we are done" or allow for better pattern matching in the URLs such as specifying the wildcard item should be an INT.
The text was updated successfully, but these errors were encountered: