<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"> </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"> </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"> func handle(request:
HTTPRequest, response: HTTPResponseWriter ) -> HTTPBodyProcessing {</font>
<br><font size=2 face="Courier New"> response.writeHeader(status:
.ok, headers: ["Transfer-Encoding": "chunked", "X-foo":
"bar"])</font>
<br><font size=2 face="Courier New"> return
.processBody { (chunk, stop) in</font>
<br><font size=2 face="Courier New">
switch chunk {</font>
<br><font size=2 face="Courier New">
case .chunk(let data, let finishedProcessing):</font>
<br><font size=2 face="Courier New">
response.writeBody(data) { _ in</font>
<br><font size=2 face="Courier New">
finishedProcessing()</font>
<br><font size=2 face="Courier New">
}</font>
<br><font size=2 face="Courier New">
case .end:</font>
<br><font size=2 face="Courier New">
response.done()</font>
<br><font size=2 face="Courier New">
default:</font>
<br><font size=2 face="Courier New">
stop = true</font>
<br><font size=2 face="Courier New">
response.abort()</font>
<br><font size=2 face="Courier New">
}</font>
<br><font size=2 face="Courier New"> }</font>
<br><font size=2 face="Courier New"> }</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>