Skip to content

Examples using Zewo's linux frameworks

License

Notifications You must be signed in to change notification settings

ZewoGraveyard/Examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Examples

Swift 3.0 Platforms Linux License MIT Slack Status

Examples using Zewo's linux frameworks

Demos

  • Server
  • Router
  • Middleware
  • File

Usage

Server

import Zewo

let log = Log()
let logger = LogMiddleware(log: log)

try Server(reusePort: true, middleware: logger) { _ in
    return Response(body: "hello")
}.start()

Router

import Zewo

let router = Router { route in
    route.get("/") { _ in
        return Response(status: .OK, body: "hello")
    }
}

try Server(responder: router).start()

Middleware

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()

File

import Zewo

try Server(responder: FileResponder(basePath: "public")).start()

Community

Slack

Join us on Slack.

License

Examples are released under the MIT license. See LICENSE for details.