Created
June 18, 2024 07:12
-
-
Save WhiteHyun/b274b6b31b1b770f90a3d625690b8381 to your computer and use it in GitHub Desktop.
Vapor with APIProtocol
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 Vapor | |
import OpenAPIRuntime | |
import OpenAPIVapor | |
struct GreetingService: APIProtocol { | |
func getGreeting(_ input: Operations.getGreeting.Input) async throws -> Operations.getGreeting.Output { | |
let name = input.query.name ?? "Stranger" | |
let greeting = Components.Schemas.Greeting(message: "Hello, \(name)!") | |
return .ok(.init(body: .json(greeting))) | |
} | |
} | |
let app = Application() | |
let transport = VaporTransport(routesBuilder: app) | |
let handler = GreetingService() | |
try handler.registerHandlers(on: transport, serverURL: .init(string: "v1")!) | |
try app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment