trait PathBindable[A] extends AnyRef
Binder for URL path parameters.
You can provide an implementation of PathBindable[A]
for any type A
you want to be able to
bind directly from the request path.
For example, given this class definition:
case class User(id: Int, name: String, age: Int)
You can define a binder retrieving a User
instance from its id, useable like the following:
// In your routes: // GET /show/:user controllers.Application.show(user) // For example: /show/42 class HomeController @Inject() (val controllerComponents: ControllerComponents) extends BaseController { def show(user: User) = Action { ... } }
The definition of binder can look like the following:
object User { implicit def pathBinder(implicit intBinder: PathBindable[Int]) = new PathBindable[User] { override def bind(key: String, value: String): Either[String, User] = { for { id <- intBinder.bind(key, value).right user <- User.findById(id).toRight("User not found").right } yield user } override def unbind(key: String, user: User): String = { intBinder.unbind(key, user.id) } } }
- Self Type
- PathBindable[A]
- Annotations
- @implicitNotFound()
- Source
- Binders.scala
- Alphabetic
- By Inheritance
- PathBindable
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def bind(key: String, value: String): Either[String, A]
Bind an URL path parameter.
Bind an URL path parameter.
- key
Parameter key
- value
The value as String (extracted from the URL path)
- returns
Right
of the value orLeft
of an error message if the binding failed
- abstract def unbind(key: String, value: A): String
Unbind a URL path parameter.
Unbind a URL path parameter.
- key
Parameter key
- value
Parameter value.
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @HotSpotIntrinsicCandidate() @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def javascriptUnbind: String
Javascript function to unbind in the Javascript router.
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def transform[B](toB: (A) => B, toA: (B) => A): PathBindable[B]
Transform this PathBinding[A] to PathBinding[B]
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
(Since version 9)