[swift-server-dev] HTTP API Review
Chris Bailey
BAILEYC at uk.ibm.com
Fri Sep 8 10:33:48 CDT 2017
In all honesty, the protocol isn't required at all.
The HTTPServer takes a HTTPRequestHandler, but that's just a typedef to:
(HTTPRequest, HTTPResponseWriter) -> HTTPBodyProcessing
So we could remove both the HTTPRequestHandling protocol and the
HTTPRequestHandler typedef and rely on the closure being defined in the
HTTPServer API - which I think Helge a while ago but that we couldn't do
at the time as HTTPServer wasn't yet in the API.
Chris
From: Andrew Dunn via swift-server-dev <swift-server-dev at swift.org>
To: swift-server-dev at swift.org
Date: 07/09/2017 16:05
Subject: Re: [swift-server-dev] HTTP API Review
Sent by: swift-server-dev-bounces at swift.org
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._______________________________________________
swift-server-dev mailing list
swift-server-dev at swift.org
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.swift.org_mailman_listinfo_swift-2Dserver-2Ddev&d=DwIGaQ&c=jf_iaSHvJObTbx-siA1ZOg&r=YUviGsMNSCx-4Qgb5i8T6YSvdr1sG-dF4qEcHRkSKOQ&m=JZMBdYZGUW6TogzveXi8ezRkhPmWqo-RsRvrk5-GZFw&s=gq3AH1os5k29tRrsmvhPmWNOTHmJHWtHvpfLZFENEsM&e=
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number
741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-server-dev/attachments/20170908/858ff2f2/attachment.html>
More information about the swift-server-dev
mailing list