Skip to content

Instantly share code, notes, and snippets.

@rymcol
Created April 25, 2016 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rymcol/ad63366e2cce18b8efa27a5fd1009af5 to your computer and use it in GitHub Desktop.
Save rymcol/ad63366e2cce18b8efa27a5fd1009af5 to your computer and use it in GitHub Desktop.
Generic boilerplate code for new Perfect handlers
import PerfectLib
//public method that is being called by the server framework to initialise your module.
public func PerfectServerModuleInit() {
 
    // Install the built-in routing handler.
    // Using this system is optional and you could install your own system if desired.
    Routing.Handler.registerGlobally()
 
    // Create Routes
    Routing.Routes["GET", ["/", "index.html"] ] = { (_:WebResponse) in return IndexHandler() }
 
    // Check the console to see the logical structure of what was installed.
    print("\(Routing.Routes.description)")
}
 
//Create a handler for index Route
class IndexHandler: RequestHandler {
 
    func handleRequest(request: WebRequest, response: WebResponse) {
        response.appendBodyString("Hello World")
        response.requestCompletedCallback()
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment