[swift-server-dev] Prototype of the discussed HTTP API Spec
Paulo Faria
paulo at zewo.io
Fri May 26 20:56:52 CDT 2017
> Was there a discussion on the module name yet? I would assume it to be
more like S3.HTTPRequest, alongside the other protocols. Or is there even
an explicit module, or just an abstract API?
There wasn't any discussion. I'm just assuming it would a module called
HTTP. Of course it could be anything else.
> It is Friday night and there about 3 opinions on that. Give it some time …
I didn't mean this is settled. I meant I'm OK with the prefixes if
eventually people decide in favor of it.
> no real complex project AFAIK had built on any of the swift web framework
available yet.
My response was to that particular section in the quote above. We do have
complex projects running in production. I'm not saying S3 is completely
mature. It isn't.
> That seems pretty optimistic given the past discussions. No protocols,
structs, enums, etc. It may be what we end up with, but I don’t
particularly like it :-) It still makes sense as a basis to go forward from.
Exactly my point. We need something to build upon. All I'm proposing is
that we start with the basics. Given the discussions we had so far the
design below looks like the most consensual (or maybe the least
controversial).
public struct HTTPVersion {
public var major: Int
public var minor: Int
public init(major: Int, minor: Int) {
self.major = major
self.minor = minor
}
}
public struct HTTPHeaders {
public var headers: [(Field, String)]
public init(_ headers: [(Field, String)]) {
self.headers = headers
}
/// Field's implementation of `Equatable` performs a case-insensitive
comparison.
public struct Field {
public let original: String
public init(_ original: String) {
self.original = original
}
}
}
public protocol HTTPMessage {
var version: HTTPVersion { get set }
var headers: HTTPHeaders { get set }
}
public struct HTTPRequest : HTTPMessage {
public var method: HTTPMethod
public var uri: String
public var version: HTTPVersion
public var headers: HTTPHeaders
public init(
method: HTTPMethod,
uri: URI,
headers: HTTPHeaders,
version: HTTPVersion
) {
self.method = method
self.uri = uri
self.headers = headers
self.version = version
}
}
public struct HTTPMethod {
public let method: String
init(_ method: String) {
self.method = method.uppercased()
}
}
public struct HTTPResponse : HTTPMessage {
public var status: HTTPStatus
public var headers: HTTPHeaders
public var version: HTTPVersion
public init(
status: HTTPStatus,
headers: HTTPHeaders,
version: HTTPVersion
) {
self.status = status
self.headers = headers
self.version = version
}
}
public struct HTTPStatus {
public let statusCode: Int
public let reasonPhrase: String
public init(statusCode: Int, reasonPhrase: String) {
self.statusCode = statusCode
self.reasonPhrase = reasonPhrase
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-server-dev/attachments/20170526/42750ed4/attachment.html>
More information about the swift-server-dev
mailing list