Comments (6)
The primary use of shapeless in rho is for the HList
type signatures. Honestly it wouldn't be too hard to just make a phantom type that can be consed like a HList
and use a normal List[Any]
for the storage, but shapeless is a transient dependency of rho so why not use it?
TypedPath
holds the 'phantom' HList
type signature and stores the path AST nodes untyped. It is known by the HList
type signature what order parameters will be produced by the path and therefor they are safe to cast to whatever they need to be. The other typed ASTs (query etc..) work the same way.
The power of the HList
phantom type comes to bear when making an action using a RouteExecutable
(many of the action building type extend this so long as they have enough information to meaningfully match a request). Here the phantom type is used to typecheck the function used to build the action. In this process you need a CompileService
in scope to get anything useful. A CompileService
can generate documentation, make a actual route etc.
That should get you started.
from rho.
Side question: what is an action, the part after the |>>
, or the whole thing?
GET / "puppy" / "bySSN" / pathVar[SSN] |>> { owner: SSN => Ok(Puppy.cutest.filter(_.lovingOwner === owner).asJson) }
Edit: and what is this expression even doing to cause the service to remember it?
from rho.
The whole thing. A RhoAction
just holds all the bits of the path definition, the function F
used to execute it (or whatever fits the HListToFunc
paired with it: F
could be a Task[Response]
or even a constant that has a EntityEncoder
), and the 'converter' which is the HListToFunc
. In turn the HListToFunc
must find a ResultMatcher
which is where some of the 'status code' magic happens, but its primary purpose is take the Request
and whatever the result of the function F
(or whatever it is) and convert that to a Task[Response]
to be shipped back to the client.
If you look at the type signature of |>>
you'll notice that it takes an implicit CompileService
which will receive the final RhoAction
and can then do whatever it likes with it. The CompileService
can be stateful and save the route (in the typical case, a route tree for matching against a request), but it doesn't have to be. For example it could simply compile it into a Request => Task[Response]]
and you get to do what you want with it, or it could generate some documentation (swagger!), whatever you like.
from rho.
P.S. Get it? The distant island kingdom is the UK.
from rho.
Is there more than one CompileService
? I could only find one, in RhoService
, so I'm probably looking for the wrong thing. If one wanted to create a new output format, what would the critical format-specific pieces be?
from rho.
Wait, I guess the critical piece is overriding RhoService#append
.
from rho.
Related Issues (20)
- Provide example using the Swagger UI Webjar HOT 1
- Got Error with http4s-scala-xml HOT 2
- NoSuchMethodError from rho 0.20.0-M1 HOT 2
- StringParser for value classes HOT 4
- Broken Links/URLs in `README.md` in branch `master` HOT 1
- Where is RhoService? HOT 2
- Feature Idea: Serving swagger in YAML
- Feature Idea: Customisable generic type names
- Is it possible to disable swagger.json endpoint and generate a plain json?
- Release v0.21.0 with swagger webjar implementation HOT 2
- Simple or-path produces incorrect tags HOT 1
- Getting 405 Method Not Allowed from combined routes HOT 3
- Demo example doesn't work HOT 1
- Non-class Scala types break TypeBuilder
- Logger Options in RhoRoutes
- Publish scala 3 artifacts HOT 3
- Getting 405 Method Not Allowed from combined routes with authentication
- Assembly doesn't like CollectionConverters
- Http4s, Scala, and main dependencies update HOT 3
- Maintainers wanted HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rho.