Skip to content

Commit

Permalink
Merge pull request #10 from llinardos/adds-patch-to-router
Browse files Browse the repository at this point in the history
Adds patch to router.
  • Loading branch information
depoon authored May 20, 2019
2 parents 72fa9e7 + 4101733 commit a8ee661
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Source/Localhost/LocalhostRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public protocol LocalhostRouter {
func post(_ path: String, routeBlock: @escaping ((URLRequest) -> LocalhostServerResponse?))
func delete(_ path: String, routeBlock: @escaping ((URLRequest) -> LocalhostServerResponse?))
func put(_ path: String, routeBlock: @escaping ((URLRequest) -> LocalhostServerResponse?))
func patch(_ path: String, routeBlock: @escaping ((URLRequest) -> LocalhostServerResponse?))
func options(_ path: String, routeBlock: @escaping ((URLRequest) -> LocalhostServerResponse?))
func head(_ path: String, routeBlock: @escaping ((URLRequest) -> LocalhostServerResponse?))

func startListening()
func stopListening()
Expand Down
9 changes: 9 additions & 0 deletions Source/Localhost/LocalhostServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ extension LocalhostServer: LocalhostRouter {
})
}

public func patch(_ path: String, routeBlock: @escaping ((URLRequest) -> LocalhostServerResponse?)) {
self.server.add(path, block: { [weak self] (req, res, next) in
self?.handleRoute(httpMethod: "PATCH",
routeBlock: routeBlock,
crRequest: req,
crResponse: res)
}, recursive: false, method: .patch)
}

public func head(_ path: String, routeBlock: @escaping ((URLRequest) -> LocalhostServerResponse?)) {
self.server.head(path, block: { [weak self] (req, res, next) in
self?.handleRoute(httpMethod: "HEAD",
Expand Down

0 comments on commit a8ee661

Please sign in to comment.