@@ -49,19 +49,7 @@ extension OpenAPILambdaRouter {
49
49
_ path: String ,
50
50
handler: @escaping @Sendable ( HTTPRequest, HTTPBody? ) async throws -> String
51
51
) throws {
52
-
53
- let openAPIHandler : OpenAPIHandler = {
54
- ( request: HTTPRequest , body: HTTPBody ? , metadata: ServerRequestMetadata ) -> ( HTTPResponse , HTTPBody ? ) in
55
-
56
- do {
57
- let response = try await handler ( request, body)
58
- return ( . init( status: . ok) , . init( response) )
59
- }
60
- catch {
61
- return ( . init( status: . internalServerError) , nil )
62
- }
63
- }
64
- try add ( method: . get, path: path, handler: openAPIHandler)
52
+ try generic ( method: . post, path: path, handler: handler)
65
53
}
66
54
67
55
/// Adds a POST route to the router for the given path.
@@ -76,6 +64,14 @@ extension OpenAPILambdaRouter {
76
64
_ path: String ,
77
65
handler: @escaping @Sendable ( HTTPRequest, HTTPBody? ) async throws -> String
78
66
) throws {
67
+ try generic ( method: . post, path: path, handler: handler)
68
+ }
69
+
70
+ func generic< Response: StringProtocol & Sendable > (
71
+ method: HTTPRequest . Method ,
72
+ path: String ,
73
+ handler: @escaping @Sendable ( HTTPRequest, HTTPBody? ) async throws -> Response
74
+ ) throws {
79
75
80
76
let openAPIHandler : OpenAPIHandler = {
81
77
( request: HTTPRequest , body: HTTPBody ? , metadata: ServerRequestMetadata ) -> ( HTTPResponse , HTTPBody ? ) in
@@ -88,6 +84,6 @@ extension OpenAPILambdaRouter {
88
84
}
89
85
}
90
86
91
- try add ( method: . post , path: path, handler: openAPIHandler)
87
+ try add ( method: method , path: path, handler: openAPIHandler)
92
88
}
93
89
}
0 commit comments