[swift-server-dev] HTTP API Review

Chris Bailey BAILEYC at uk.ibm.com
Mon Aug 21 14:53:55 CDT 2017

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.

The main documentation for the HTTP API is now available via GitHub Pages 
which describes the use of a "WebApp" to handle an incoming HTTPRequest 
and build a response.

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:

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:

class SimpleHandler: HTTPRequestHandling {
    func handle(request: HTTPRequest, response: HTTPResponseWriter ) -> 
HTTPBodyProcessing {
        response.writeHeader(status: .ok, headers: ["Transfer-Encoding": 
"chunked", "X-foo": "bar"])
        return .processBody { (chunk, stop) in
            switch chunk {
            case .chunk(let data, let finishedProcessing):
                response.writeBody(data) { _ in
            case .end:
                stop = true

let server = SimpleHTTPServer()

try! server.start(port: 0, handler: SimpleHandler().handle)

Please take a look and provide feedback, for example, suggesting that 
SimpleHTTPServer should just be HTTPServer ;-)


Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 
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/20170821/61fe34a9/attachment.html>

More information about the swift-server-dev mailing list