Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to RoutingHandlers for Swift 4 / Perfect 3 #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Sources/RoutingHandlers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ func makeURLRoutes() -> Routes {
var api2Routes = Routes(baseUri: "/v2")

// Add the main API calls to version 1
api1Routes.add(routes: api)
api1Routes.add(api)
// Add the main API calls to version 2
api2Routes.add(routes: api)
api2Routes.add(api)
// Update the call2 API
api2Routes.add(method: .get, uri: "/call2", handler: { _, response in
response.setBody(string: "API v2 CALL 2")
response.completed()
})

// Add both versions to the main server routes
routes.add(routes: api1Routes)
routes.add(routes: api2Routes)
routes.add(api1Routes)
routes.add(api2Routes)

// Check the console to see the logical structure of what was installed.
print("\(routes.navigator.description)")
Expand Down Expand Up @@ -101,7 +101,8 @@ func echo4Handler(request: HTTPRequest, _ response: HTTPResponse) {
}

func rawPOSTHandler(request: HTTPRequest, _ response: HTTPResponse) {
response.appendBody(string: "<html><body>Raw POST handler: You POSTED to path \(request.path) with content-type \(request.header(.contentType)) and POST body \(request.postBodyString)</body></html>")
// see https://stackoverflow.com/a/42543251 for explanation of "as Optional" usage
response.appendBody(string: "<html><body>Raw POST handler: You POSTED to path \(request.path) with content-type \(request.header(.contentType) as Optional) and POST body \(request.postBodyString as Optional)</body></html>")
response.completed()
}