Open dannywillems opened 7 years ago
Sounds very complicated. If we were to provide such a syntax, it would have to be very Eliom-specific to account for the Eliom typing of services and parameters. And then we have the issue of how to map this syntax to properly-typed code calling Eliom_registration.X.register
(and similar functions).
@vasilisp What I would it's only to be able to parse configuration file like those from Play, which I don't think it's complicated.
We can provide a function Eliom_services.from_file filename
which returns a list of services.
We can provide a function Eliom_services.from_file filename
Eliom_services.from_file filename
What would be the type of the returned list?
Oh... I see what @vasilisp means.
For example, consider a declaration like:
GET /users/:username controllers.Users.showUser(username: String)
What would we do, or what would we put in the list? From my point of view, we would need to register a service with an appropriate suffix parameter and with Controllers.Users.show_user : string -> ...
as the service handler.
The only way I can imagine implementing such a thing with OCaml/Eliom would be via a compiler "frontend" that reads this file and produces Eliom_registration.X.create
calls (with appropriate paths and parameters). That could be quite an interesting project actually.
I am curious how the Java people do this. Introspection? Practically untyped handlers?
The only way I can imagine implementing such a thing with OCaml/Eliom would be via a compiler "frontend" that reads this file and produces Eliom_registration.X.create calls (with appropriate paths and parameters). That could be quite an interesting project actually.
So, a ppx ? :) That's exactly what the prototype tyxml template does.
I didn't call it PPX because the input is not Ocaml code with extension points, but yes, that kind of thing :).
Even if Eliom can define more services types than most web frameworks, it would be interesting to be compatible with other routes definitions of those other web frameworks (which are often in a text file). In this way, if someone wants to change to Eliom, it can copy the configuration file.
For example, Play (Scala & Java) uses a simple routes configuration file, see here.