WebAppContaining
public protocol WebAppContaining: class
Class protocol containing the WebApp that responds to the incoming HTTP requests. The following is an example of a WebApp that returns the request as a response:
class EchoWebApp: WebAppContaining {
func serve(req: HTTPRequest, res: HTTPResponseWriter ) -> HTTPBodyProcessing {
res.writeHeader(status: .ok, headers: [:])
return .processBody { (chunk, stop) in
switch chunk {
case .chunk(let data, let finishedProcessing):
res.writeBody(data) { _ in
finishedProcessing()
}
case .end:
res.done()
default:
stop = true
res.abort()
}
}
}
}
-
serve: function called when a new HTTP request is received by the HTTP server.
Declaration
Swift
func serve(req: HTTPRequest, res: HTTPResponseWriter ) -> HTTPBodyProcessingParameters
reqthe incoming HTTP request.
resan writer providing functions to create an HTTP reponse to the request.
View on GitHub
WebAppContaining Protocol Reference