Contents

perfectlysoft/perfect-httpserver

HTTP Server for Perfect

QuickStart

Add the dependency to your Package.swift

.package(url: "https://github.com/PerfectlySoft/Perfect-HTTPServer.git", from: "3.0.0")

In your app, launch one or more servers.

// start a single server serving static files
try HTTPServer.launch(name: "localhost", port: 8080, documentRoot: "/path/to/webroot")
 
// start two servers. have one serve static files and the other handle API requests
let apiRoutes = Route(method: .get, uri: "/foo/bar", handler: {
        req, resp in
        //do stuff
    })
try HTTPServer.launch(
    .server(name: "localhost", port: 8080, documentRoot:  "/path/to/webroot"),
    .server(name: "localhost", port: 8181, routes: [apiRoutes]))
 
// start a single server which handles API and static files
try HTTPServer.launch(name: "localhost", port: 8080, routes: [
    Route(method: .get, uri: "/foo/bar", handler: {
        req, resp in
        //do stuff
    }),
    Route(method: .get, uri: "/foo/bar", handler:
        HTTPHandler.staticFiles(documentRoot: "/path/to/webroot"))
    ])
 
let apiRoutes = Route(method: .get, uri: "/foo/bar", handler: {
        req, resp in
        //do stuff
    })
// start a secure server
try HTTPServer.launch(.secureServer(TLSConfiguration(certPath: "/path/to/cert"), name: "localhost", port: 8080, routes: [apiRoutes]))

Documentation

For further information, please visit perfect.org.

Package Metadata

Repository: perfectlysoft/perfect-httpserver

Default branch: master

README: README.md