Created
July 1, 2021 12:51
-
-
Save pallavtrivedi03/ef5b77ebd73b23a50f6c94d45a8fcf96 to your computer and use it in GitHub Desktop.
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 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