diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-08-09 00:39:48 +0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-08-09 00:39:48 +0800 |
commit | 0c1ebbd786ff97e525025a1aaed59dd4d5b512ca (patch) | |
tree | 30331496c113f141e85779f0aad175e7446cbb97 /cask | |
parent | 2be53fc2b699de871e5decc9a94d975105516e79 (diff) | |
download | cask-0c1ebbd786ff97e525025a1aaed59dd4d5b512ca.tar.gz cask-0c1ebbd786ff97e525025a1aaed59dd4d5b512ca.tar.bz2 cask-0c1ebbd786ff97e525025a1aaed59dd4d5b512ca.zip |
Allow for optional query params
Diffstat (limited to 'cask')
-rw-r--r-- | cask/src/cask/endpoints/WebEndpoints.scala | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/cask/src/cask/endpoints/WebEndpoints.scala b/cask/src/cask/endpoints/WebEndpoints.scala index 70d16e0..2125b4d 100644 --- a/cask/src/cask/endpoints/WebEndpoints.scala +++ b/cask/src/cask/endpoints/WebEndpoints.scala @@ -58,6 +58,12 @@ object QueryParamReader{ v.map(x => implicitly[QueryParamReader[T]].read(ctx, label, Seq(x))) } } + implicit def OptionParam[T: QueryParamReader] = new QueryParamReader[Option[T]]{ + def arity = 1 + def read(ctx: cask.model.ParamContext, label: String, v: Seq[String]): Option[T] = { + v.headOption.map(x => implicitly[QueryParamReader[T]].read(ctx, label, Seq(x))) + } + } implicit def paramReader[T: ParamReader] = new QueryParamReader[T] { override def arity = 0 |