[swift-server-dev] HTTP API Review
Chris Bailey
BAILEYC at uk.ibm.com
Fri Sep 8 10:33:47 CDT 2017
>> - `HTTPBodyProcessing` is a very long word with no obvious meaning.
Agreed, the naming here could be clearer as to what its purpose is. Do you
have any suggestions?
>> - I would use `HTTPResponse` instead of `HTTPResponseWriter`
The use of HTTPResponseWriter here is very deliberate because eventually
the API should be symmetrical for the server and client use cases, ie: a
server has access to a HTTPRequest and a HTTPResponseWriter, and a client
has access to a HTTPRequestWriter and a HTTPResponse.
>> - I would rename `writeBody` to `write` (and, maybe, `writeHeader` to
`addHeader`, `setHeader`, `appendHeader` or something similar)
I think if we we're to switch to using "write()" for writeBody(), then
we'd have to move to:
func write(headers: HTTPHeaders, status: HTTPResponseStatus,
completion: @escaping (Result) -> Void)
func write(body: UnsafeHTTPResponseBody, completion: @escaping
(Result) -> Void)
How does that look?
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: 04/09/2017 20:26
Subject: Re: [swift-server-dev] HTTP API Review
Also,
- `HTTPBodyProcessing` is a very long word with no obvious meaning.
- I would use `HTTPResponse` instead of `HTTPResponseWriter`
- I would rename `writeBody` to `write` (and, maybe, `writeHeader` to
`addHeader`, `setHeader`, `appendHeader` or something similar)
-g.
On 3 Sep 2017, at 8:51 PM, Chris Bailey <BAILEYC at uk.ibm.com> wrote:
Hi Georgios:
The protocol which the class needs to implement is 'HTTPRequestHandling'
but the class can have any name the user wants to use. I agree that for
the documentation (and the tests!) the use of 'Handler' is confusing and
could be better. How does the following look as a sample "Hello World"
app?
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
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/ee491cef/attachment.html>
More information about the swift-server-dev
mailing list