Service
public class Service
A Service is a basic HTTP server. Each incoming request will trigger the provided
handler to fire. The handler implementation is responsible for routing, parsing, or
any other custom behaviour then populating the Response as necessary.
-
Initializes a new Service with the provided request handler.
Warning
The provided handler must call
send()on the providedResponsein order to return a response to the client. Failure to do so will cause the connection to hang until the client times out.Note
send()is called automatically when using any of thewrite()convenience methods.Declaration
Swift
public init(logger: Logger? = nil, handler: @escaping RequestHandler)Parameters
loggerA Logger instance. If one is not provided, a default will be created.
handlerThe request handler.
-
Starts the Service listening on the provided port.
Declaration
Swift
public func listen(port: Int = 5000) -
A
Loggerinstance used throughout the Service.Note
A default Logger will be created if one is not provided ininit()See also
swift-logDeclaration
Swift
public let logger: Logger
View on GitHub
Service Class Reference