[swift-server-dev] HTTP API Review

Andrew Dunn andrew.a.dunn at icloud.com
Thu Sep 7 10:04:34 CDT 2017


IMHO both ‘HTTPRequestHandling' and ‘HTTPRequestHandler' conform to the Swift API Design Guidelines, the ability to handle HTTP requests is a capability after all.

However, there’s just something about the name ‘HTTPRequestHandling' which seems… off… Maybe because the word “handling” is a verb (in the present-tense no less)? To make it an adjective it would have to be named something like: “HandlesHTTPRequests”. But that would be in breach of the style guidelines.

Is it just me, or is the current usage of ‘HTTPRequestHandler’ identifier wasted on syntactic sugar for the relatively unlikely scenario where a closure is provided to HTTPServing.start()? Perhaps the identifier could be used for the protocol instead, and the method that takes a closure could wrap the closure in a class implementing the protocol? Would look something like so:

    public func start(port: Int = 0, handler: HTTPRequestHandler) throws {
        try server.start(handler: handler)
    }

    public func start(port: Int = 0, _ handlingClosure: @escaping HTTPRequestHandlingClosure) throws {
        try self.start(handler: HTTPRequestHandlingClosureWrapper(handlingClosure))
    }

Cheers,
Andrew.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-server-dev/attachments/20170908/dd92a04d/attachment.html>


More information about the swift-server-dev mailing list