Examples using Zewo's linux frameworks
- Server
- Router
- Middleware
- File
import Zewo
let log = Log()
let logger = LogMiddleware(log: log)
try Server(reusePort: true, middleware: logger) { _ in
return Response(body: "hello")
}.start()
import Zewo
let router = Router { route in
route.get("/") { _ in
return Response(status: .OK, body: "hello")
}
}
try Server(responder: router).start()
import Zewo
let log = Log()
let logger = LogMiddleware(log: log)
let parsers = MediaTypeParserCollection()
parsers.add(JSONMediaType, parser: JSONInterchangeDataParser())
parsers.add(URLEncodedFormMediaType, parser: URLEncodedFormInterchangeDataParser())
let serializers = MediaTypeSerializerCollection()
serializers.add(JSONMediaType, serializer: JSONInterchangeDataSerializer())
serializers.add(URLEncodedFormMediaType, serializer: URLEncodedFormInterchangeDataSerializer())
let contentNegotiation = ServerContentNegotiationMiddleware(
parsers: parsers,
serializers: serializers
)
try Server(middleware: logger, contentNegotiation) { _ in
let content: InterchangeData = [
"foo": "bar",
"hello": "world"
]
return Response(content: content)
}.start()
import Zewo
try Server(responder: FileResponder(basePath: "public")).start()
Join us on Slack.
Examples are released under the MIT license. See LICENSE for details.