Skip to content

Instantly share code, notes, and snippets.

@pallavtrivedi03
Created July 1, 2021 12:51
Show Gist options
  • Save pallavtrivedi03/ef5b77ebd73b23a50f6c94d45a8fcf96 to your computer and use it in GitHub Desktop.
Save pallavtrivedi03/ef5b77ebd73b23a50f6c94d45a8fcf96 to your computer and use it in GitHub Desktop.
import Foundation
import PerfectLib
import PerfectHTTP
import PerfectHTTPServer
class FlightsListController {
func handleFlightsListRequest(request: HTTPRequest, response: HTTPResponse) {
do {
try response.setBody(json: getFlightsList())
.setHeader(.contentType, value: "application/json")
.completed(status: .ok)
} catch {
response.setBody(string: "Something went wrong")
.completed(status: .internalServerError)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment