[swift-server-dev] HTTP API Review
Georgios Moschovitis
george.moschovitis at icloud.com
Mon Sep 4 14:16:56 CDT 2017
> How does the following look as a sample "Hello World" app?
Looks much better to me. I would prefer the following though:
import HTTP
func handler(request: HTTPRequest, response: HTTPResponseWriter ) -> HTTPBodyProcessing {
response.writeHeader(status: .ok)
response.writeBody("Hello, World!")
response.done()
return .discardBody
}
try! HTTPServer().start(port: 8080, handler: handler)
>
> import HTTP
>
> class MyServer: HTTPRequestHandling {
> func handle(request: HTTPRequest, response: HTTPResponseWriter ) -> HTTPBodyProcessing {
> response.writeHeader(status: .ok)
> response.writeBody("Hello, World!")
> response.done()
> return .discardBody
> }
> }
>
> let server = HTTPServer()
>
> try! server.start(port: 8080, handler: MyServer().handle)
>
>
> Chris
>
>
>
> From: Georgios Moschovitis <george.moschovitis at icloud.com>
> To: Chris Bailey <BAILEYC at uk.ibm.com>
> Cc: swift-server-dev at swift.org
> Date: 03/09/2017 07:44
> Subject: Re: [swift-server-dev] HTTP API Review
>
>
>
> Had a (very) quick look, and in general it looks OK.
> One thing that bothers me in the example is this ***Handler <-> ***Handling inconsistency..
>
> class SimpleHandler: HTTPRequestHandling
>
> maybe something like
>
> class WebApp: HTTPRequestHandling {
> ...
> }
>
> would make it less confusing?
>
> -g.
>
>
>
> 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/20170904/10d80c84/attachment.html>
More information about the swift-server-dev
mailing list