[swift-server-dev] HTTPMethod, was: Re: Next HTTP API meeting

Helge Heß me at helgehess.eu
Thu Mar 23 06:11:58 CDT 2017


On 23 Mar 2017, at 11:18, Logan Wright via swift-server-dev <swift-server-dev at swift.org> wrote:
> some types that I think are pretty unambiguous like HTTPMethod

May I ask how that would look like in your opinion? I was thinking about that too, and I find it rather hard to come up with a really good solution.

The desirable thing would be an enum, but such can’t be extended in Swift w/o an associated value. Like so

  enum HTTPMethod {
    case GET, REPORT, MKCALENDAR, CHECKOUT, …
    case ExtendedMethod(String)
  }

But I think this would be pretty weird for ‘late’ methods and you’d end up with code like

  switch method {
    case .get: ...
    case ExtendedMethod(“PATCH”): ...
  }

which will look really weird quickly. New methods do not come around every day, but more often than you might think (note explicit support for arbitrary ones in todays XHR, this used to support only GET/POST, hence the xhr-method header thing).

hh



More information about the swift-server-dev mailing list