You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Specifications that can be used to self describe (e.g. Swagger, JSON HAL) web services use URI RFC3986 and URI Template RFC6570 often.
It would be helpful be able to transform a route definition into a URI or URI Template. For example, this would lower the amount of redundant code when working with JSON HAL to describe references to other resources within a specific resource.
objectMyWebService {
valstartParam= query[Int]("start", 0)
vallimitParam= query[Int]("limit", 0)
valorders=GET/"orders"valordersSearch=GET/"orders"+? query[String]("searchterm")
valordersPaginated= orders +? startParam & limitParam
valorder= orders / pathVar[Int]
valorderItems= orders / pathVar[Int] /"items"+? startParam & limitParam
// what we can do todayvalservice1=newRhoService {
ordersPaginated |>> { (start: Int, limit: Int) =>"return page of orders"
}
order |>> { id: Int=>s"return order with id $id"
}
orderItems |>> { (id: Int, start: Int, limit: Int) =>s"return page of items from order with id $id"
}
}
// what we need for JSON HALvalservice2=newRhoService {
ordersPaginated |>> { (start: Int, limit: Int) =>ResourceObject[Map[String, Any]](
Vector(
"self"->Single(LinkObject(self.toUri)), // self should be implicitly available"next"->Single(LinkObject(orders.toUri +? startParam(start + limit))),
"search"->Single(LinkObject(ordersSearch.toUriTemplate))),
Vector.empty,
Some(Map("orders"->List(1, 2, 3, 4, 5, 6, 7, 8, 9)))))
}
order |>> { id: Int=>ResourceObject[Map[String, Any]](
Vector(
"self"->Single(LinkObject(self.toUri)), // self should be implicitly available"items"->Single(LinkObject(orderItems(id).toUri))),
Vector.empty,
Some(Map("items"->List(1, 2, 3, 4, 5, 6, 7, 8, 9))))
}
orderItems |>> { (id: Int, start: Int, limit: Int) =>ResourceObject[Map[String, Any]](
Vector(
"self"->Single(LinkObject(orders.toUri)),
"next"->Single(LinkObject(orders.toUri +? startParam(start + limit)))),
Vector.empty,
Some(Map("items"->List("concrete item 1", "concrete item 2" ... ))))
}
}
}
The text was updated successfully, but these errors were encountered:
arouel
changed the title
Support URI and URI template in route definition and vice versa
Provide URI and URI template of a route definition
Jul 4, 2014
+1. I think this should be doable, though the syntax may be a bit different particularly when using the dsl template as a function startParam(start + limit). We'll see what can be done.
Specifications that can be used to self describe (e.g. Swagger, JSON HAL) web services use URI RFC3986 and URI Template RFC6570 often.
It would be helpful be able to transform a route definition into a URI or URI Template. For example, this would lower the amount of redundant code when working with JSON HAL to describe references to other resources within a specific resource.
The text was updated successfully, but these errors were encountered: