FlyingFox icon indicating copy to clipboard operation
FlyingFox copied to clipboard

Why is HTTPRoute.method not of type HTTPMethod?

Open tonyarnold opened this issue 1 year ago • 5 comments

https://github.com/swhitty/FlyingFox/blob/b3f2ed19bd05d1228949a5548efce06a69850143/FlyingFox/Sources/HTTPRoute.swift#L35

I'm working on a solution for #89, and I've noticed that this property is typed as a Component. I'd love to know more before I start making changes?

tonyarnold avatar Jun 06 '24 05:06 tonyarnold

I just made up the syntax one day with some regrets now, but this was really just to allow routes to any HTTPMethod

/foo is equivalent to * /foo

Using Component was just lazy reuse of the same type representing the path components, so happy for that to change. It could simply be HTTPMethod? with nil representing the wildcard or something else if we wanted to express a finite subset of methods

(GET,PUT) /foo etc.

swhitty avatar Jun 06 '24 10:06 swhitty

The other regret is interpreting a trailing * as a recursive subpath

/hello/* matches both /hello/fish AND /hello/fish/chips.

I would have now preferred to be explicit about this using ** for this recursive subpath matching

swhitty avatar Jun 06 '24 10:06 swhitty

I hadn't considered a subset of methods. ~Perhaps it should be an OptionSet, or an array of HTTPMethod… I'll play with the OptionSet idea.~

I forgot that OptionSets are numeric. The stringiness is good here, I think.

tonyarnold avatar Jun 06 '24 10:06 tonyarnold

The stringiness is good here

Agreed, one may want to test using non standard methods for whatever reason.

swhitty avatar Jun 07 '24 23:06 swhitty

What about something like:

GET /some-url-1
GET,PUT,POST /some-url-2
/some-url-3

Not specifying a method currently seems to infer all methods — perhaps this should be restricted to GET in future.

That's simple enough to parse.

It would mean making the var method: Method into something like var methods: Set<Method>.

tonyarnold avatar Jun 14 '24 03:06 tonyarnold

I plan on pushing out 0.15.0 later this week which includes these changes.

swhitty avatar Jul 10 '24 22:07 swhitty

Wonderful, thanks Simon! I'm sorry I haven't made much time to look at my follow on changes over the last few weeks. I'll try to make some time.

tonyarnold avatar Jul 10 '24 22:07 tonyarnold

Released in 0.15.0

swhitty avatar Jul 15 '24 00:07 swhitty