This repository has been archived by the owner on Jan 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from broadinstitute/ks_api_routing
Added a `WrappedRoute` for ultimately protecting /api.
- Loading branch information
Showing
6 changed files
with
565 additions
and
55 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package lenthall.spray | ||
|
||
import spray.routing._ | ||
import spray.routing.directives.PathDirectives | ||
|
||
object WrappedRoute { | ||
|
||
/** | ||
* Wraps a route with a prefix. | ||
* Can optionally serve the wrapped route, and the original unwrapped route, until clients are all switched over. | ||
* | ||
* @param unwrappedRoute The original unwrapped route. | ||
*/ | ||
implicit class EnhancedWrappedRoute(val unwrappedRoute: Route) extends AnyVal { | ||
/** | ||
* | ||
* @param wrappedPathPrefix The prefix to wrap unwrapped route. Ex: "api" (implicitly converted to a PathMatcher) | ||
* @param routeUnwrapped For legacy reasons, should we also serve up the unwrapped route? Defaults to false. | ||
* @return The wrappedRoute, followed optionally by the unwrappedRoute if routeUnwrapped is true. | ||
*/ | ||
def wrapped(wrappedPathPrefix: PathMatcher0, routeUnwrapped: Boolean = false): Route = { | ||
import PathDirectives._ | ||
import RouteConcatenation._ | ||
val route = pathPrefix(wrappedPathPrefix) { | ||
unwrappedRoute | ||
} | ||
if (routeUnwrapped) route ~ unwrappedRoute else route | ||
} | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"title": "Test Service API", | ||
"description": "Test Service API", | ||
"version": "1.2.3" | ||
}, | ||
"produces": [ | ||
"application/json" | ||
], | ||
"paths": { | ||
"/hello": { | ||
"get": { | ||
"responses": { | ||
"200": { | ||
"description": "Says hello via get" | ||
} | ||
} | ||
}, | ||
"post": { | ||
"responses": { | ||
"200": { | ||
"description": "Says hello via post" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
swagger: '2.0' | ||
info: | ||
title: Test Service API | ||
description: Test Service API | ||
version: 1.2.3 | ||
produces: | ||
- application/json | ||
paths: | ||
/hello: | ||
get: | ||
responses: | ||
'200': | ||
description: Says hello via get | ||
post: | ||
responses: | ||
'200': | ||
description: Says hello via post |
Oops, something went wrong.