<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div> Hi Chris,<div><br></div><div>Well I do not participate in the server workgroup, but I do track its evolution from time to time. I Also haven’t used the new API as a library to play around with, but I had a quick glance over the API.</div><div><br></div><div>There are a few questions and suggestions to simplify the evolution of the server side APIs in general:</div><div><br></div><div>- (I haven’t tracked that particular decision) Why not calling the module `HTTP`?</div><div>- Even it the module is currently called `SwiftServerHTTP`, isn’t the HTTP type prefix redundant?</div><div>&nbsp; &nbsp; - If the Module was called `HTTP` then you could use `HTTP.Method` if you wanted or simply omit the HTTP because it would be optional.</div><div><br></div><div>+ I would highly suggest to include a swift lint file so that everyone who’s working on the code follows the same code style rules. (https://github.com/realm/SwiftLint)</div><div>&nbsp; &nbsp; + case/default is part of switch statement itself - indent violation:&nbsp;<a href="https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPHeaders.swift#L21">https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPHeaders.swift#L21</a>&nbsp;(there are a lot more of these)</div><div>&nbsp; &nbsp; + use optional unwrapping instead - avoid force cast:&nbsp;<a href="https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPHeaders.swift#L75">https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPHeaders.swift#L75</a></div><div>&nbsp; &nbsp; + whitespace violation:&nbsp;<a href="https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPResponse.swift#L15">https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPResponse.swift#L15</a></div><div>&nbsp; &nbsp; + missing whitespace for inheritance / conformance before the colon:&nbsp;<a href="https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPResponse.swift#L85">https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPResponse.swift#L85</a></div><div>&nbsp; &nbsp; + use whitespaces around operators:&nbsp;<a href="https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPResponse.swift#L321">https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPResponse.swift#L321</a></div><div>&nbsp; &nbsp; + use whitespaces around assigning operator:&nbsp;<a href="https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPStreamingParser.swift#L186">https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPStreamingParser.swift#L186</a></div><div>&nbsp; &nbsp; + either omit `self` as much as Swift allows or write it everywhere possible</div><div>&nbsp; &nbsp; + probably longer than the 120 character width - choose one, either 80 or 120:&nbsp;<a href="https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPStreamingParser.swift#L118">https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPStreamingParser.swift#L118</a></div><div>&nbsp; &nbsp; + unnecessary new line:&nbsp;<a href="https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPStreamingParser.swift#L465">https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPStreamingParser.swift#L465</a></div><div>&nbsp; &nbsp; + missing back ticks around `get`:&nbsp;<a href="https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPMethod.swift#L25">https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPMethod.swift#L25</a></div><div>&nbsp; &nbsp; + missing whitespace after the operator in declaration:&nbsp;<a href="https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPResponse.swift#L352">https://github.com/swift-server/http/blob/develop/Sources/HTTP/HTTPResponse.swift#L352</a></div><div><br></div><div>These are a couple of things that my eyes could catch at a quick glance.</div><div><br></div><div>Here are the rules I’m using in a project:</div><div><br></div><div>```</div><div><div>opt_in_rules:</div><div>&nbsp; - closure_end_indentation</div><div>&nbsp; - closure_spacing</div><div>&nbsp; - fatal_error_message</div><div>&nbsp; - force_unwrapping</div><div>&nbsp; - sorted_imports</div><div>&nbsp; - operator_usage_whitespace</div><div>&nbsp; - redundant_nil_coalescing</div><div>&nbsp; - switch_case_on_newline</div><div>&nbsp; - attributes</div><div>&nbsp; - no_extension_access_modifier</div><div>&nbsp; - implicit_return</div><div><br></div><div># rule identifiers to exclude from running</div><div>disabled_rules:&nbsp;</div><div>&nbsp; - colon</div><div>&nbsp; - closure_parameter_position</div><div>&nbsp; - opening_brace</div><div>&nbsp; - file_length</div><div>&nbsp; - implicit_return</div><div><br></div><div>identifier_name:</div><div>&nbsp; # excluded via string array</div><div>&nbsp; excluded:&nbsp;</div><div>&nbsp; &nbsp; - px</div><div><br></div><div>large_tuple: 4</div><div><br></div><div>cyclomatic_complexity: 15</div><div><br></div><div>nesting:</div><div>&nbsp; type_level: 2</div><div><br></div><div>trailing_whitespace:</div><div>&nbsp; ignores_empty_lines: true</div><div>&nbsp; ignores_comments: true</div><div><br></div><div>attributes:</div><div>&nbsp; always_on_same_line: ["@IBAction", "@IBOutlet", "@IBInspectable"]</div><div>&nbsp; always_on_line_above: ["@IBDesignable", "@UIApplicationMain", "@discardableResult", "@objc"]</div></div><div>```<br> <div id="bloop_sign_1503386027169431808" class="bloop_sign"></div> <br><p class="airmail_on">Am 21. August 2017 um 21:54:38, Chris Bailey via swift-server-dev (<a href="mailto:swift-server-dev@swift.org">swift-server-dev@swift.org</a>) schrieb:</p> <blockquote type="cite" class="clean_bq"><span><div><div></div><div>


<title></title>


<font size="2" face="sans-serif">The HTTP part of the Swift Server
API project has undergone a number of iterations and updates, and I
believe its approaching the point that we have sufficient function
for use to raise a Swift Evolution "Pitch" and give the wider user
community and opportunity to try out the APIs and provide some
early feedback.</font><br>
<br>
<font size="2" face="sans-serif">The main documentation for the
HTTP API is now available via GitHub Pages here:</font><br>
<font size="2" face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp;</font>
<a href="https://swift-server.github.io/http/"><font size="2" color="blue" face="sans-serif">https://swift-server.github.io/http/</font></a><br>
<font size="2" face="sans-serif">which describes the use of a
"WebApp" to handle an incoming HTTPRequest and build a
response.</font><br>
<br>
<font size="2" face="sans-serif">The main item that's missing is a
minimal set of APIs to create the HTTP server itself, and to rename
the "WebApp" to something better. The following PR from Ian
Partridge proposes to do that:</font><br>
<font size="2" face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp;</font>
<a href="https://github.com/swift-server/http/pull/26"><font size="2" color="blue" face="sans-serif">https://github.com/swift-server/http/pull/26</font></a><br>

<br>
<font size="2" face="sans-serif">This renames "WebApp" to
"HTTPRequestHandler" provides a "SimpleHTTPServer" implementation
with start() and stop() functions. This means you can create and
run a simple server with the following:</font><br>
<br>
<font size="2" face="Courier New">class SimpleHandler:
HTTPRequestHandling {</font><br>
<font size="2" face="Courier New">&nbsp; &nbsp; func
handle(request: HTTPRequest, response: HTTPResponseWriter ) -&gt;
HTTPBodyProcessing {</font><br>
<font size="2" face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp;
response.writeHeader(status: .ok, headers: ["Transfer-Encoding":
"chunked", "X-foo": "bar"])</font><br>
<font size="2" face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp;
return .processBody { (chunk, stop) in</font><br>
<font size="2" face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; switch chunk {</font><br>
<font size="2" face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; case .chunk(let data, let
finishedProcessing):</font><br>
<font size="2" face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; response.writeBody(data) { _
in</font><br>
<font size="2" face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
finishedProcessing()</font><br>
<font size="2" face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; }</font><br>
<font size="2" face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; case .end:</font><br>
<font size="2" face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; response.done()</font><br>
<font size="2" face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; default:</font><br>
<font size="2" face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; stop = true</font><br>
<font size="2" face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; response.abort()</font><br>
<font size="2" face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; }</font><br>
<font size="2" face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp;
}</font><br>
<font size="2" face="Courier New">&nbsp; &nbsp; }</font><br>
<font size="2" face="Courier New">}</font><br>
<br>
<font size="2" face="Courier New">let server =
SimpleHTTPServer()</font><br>
<br>
<font size="2" face="Courier New">try! server.start(port: 0,
handler: SimpleHandler().handle)</font><br>
<br>
<font size="2" face="sans-serif">Please take a look and provide
feedback, for example, suggesting that SimpleHTTPServer should just
be HTTPServer ;-)</font><br>
<br>
<font size="2" face="sans-serif">Thanks,</font><br>
<br>
<font size="2" face="sans-serif">Chris<br>
Unless stated otherwise above:<br>
IBM United Kingdom Limited - Registered in England and Wales with
number 741598.<br>
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire
PO6 3AU<br></font>


_______________________________________________<br>swift-server-dev mailing list<br>swift-server-dev@swift.org<br>https://lists.swift.org/mailman/listinfo/swift-server-dev<br></div></div></span></blockquote></div></body></html>