File tree Expand file tree Collapse file tree 2 files changed +21
-6
lines changed Expand file tree Collapse file tree 2 files changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -38,8 +38,16 @@ public struct HTTPRoute {
3838
3939 public init ( _ string: String ) {
4040 let comps = Self . components ( for: string)
41- self . method = Component ( comps. method)
42- self . path = comps. path
41+ self . init ( method: comps. method, path: comps. path)
42+ }
43+
44+ public init ( method: HTTPMethod , path: String ) {
45+ self . init ( method: method. rawValue, path: path)
46+ }
47+
48+ init ( method: String , path: String ) {
49+ self . method = Component ( method)
50+ self . path = path
4351 . split ( separator: " / " , omittingEmptySubsequences: true )
4452 . map { Component ( String ( $0) ) }
4553 }
@@ -119,3 +127,10 @@ public extension HTTPRoute {
119127 }
120128
121129}
130+
131+ extension HTTPRoute : ExpressibleByStringLiteral {
132+
133+ public init ( stringLiteral value: String ) {
134+ self . init ( value)
135+ }
136+ }
Original file line number Diff line number Diff line change @@ -45,12 +45,12 @@ public final actor HTTPServer {
4545 self . handlers = [ ]
4646 }
4747
48- public func appendHandler( for route: String , handler: HTTPHandler ) {
49- handlers. append ( ( HTTPRoute ( route) , handler) )
48+ public func appendHandler( for route: HTTPRoute , handler: HTTPHandler ) {
49+ handlers. append ( ( route, handler) )
5050 }
5151
52- public func appendHandler( for route: String , closure: @escaping ( HTTPRequest ) async throws -> HTTPResponse ) {
53- handlers. append ( ( HTTPRoute ( route) , ClosureHTTPHandler ( closure) ) )
52+ public func appendHandler( for route: HTTPRoute , closure: @escaping ( HTTPRequest ) async throws -> HTTPResponse ) {
53+ handlers. append ( ( route, ClosureHTTPHandler ( closure) ) )
5454 }
5555
5656 public func start( ) async throws {
You can’t perform that action at this time.
0 commit comments