Created
April 25, 2016 19:27
-
-
Save rymcol/ad63366e2cce18b8efa27a5fd1009af5 to your computer and use it in GitHub Desktop.
Generic boilerplate code for new Perfect handlers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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