Hello all,
The question is: Is there a way to run a proc from a module based only on the strings that represent the identifiers? Something like:
allmodules("mymodule").moduleprocs("myproc")(param1, param2)
Or if that is impossible only:
moduleprocs("myproc")(param1, param2)
Background. I use Jester and have created some server-nim-code, that i want to call from the client-side (browser). I dont want to rewrite the code for the client-side in javascript. I want to use javascript only for the events, but reuse the procedures from the nim-server-side. I know you can compile to javascript but it seems simpler to pipe procedure-calls thru the cookie-system from the client-side to the server-side (what i call a cookie-tunnel). But you can only pipe strings, so therefore it would be usefull to have a command like above.
Otherwise I must do it indirectly with an if-statement which is little less elegant:
Maybe there are more advanced ways to call nim-server-code from javascript; I am glad to hear it, hopefully not too complicated :-)
Check out my tiny library https://github.com/Niminem/Neel
It makes client/server communication seamless, similar to how you mention
@ Niminem. It is an interesting framework but I have my own little framework :-)
I would like to hear a more elaborate, abstract explanation of how your framework works, as opposed to a recipe for usage, before i invest time in trying in out. I dont see the word cookie mentioned in your code so I guess you use another communication-mechanism between client and server. At this moment I just want to implement a basic cookie-tunnel. Also because I have not yet invested time in understanding macros, at this time i dont want to depend to much on macros because i want to understand the code I use. In the future I will certainly study macros, if time permits. Thanks anyway.
I know you can compile to javascript but it seems simpler to pipe procedure-calls thru the cookie-system from the client-side to the server-side
That's odd... Just use fetch to call the endpoint in Nim, you'll need basic routing to target your endpoints
It may be a poor choice but it is a working choice now :-)
https://github.com/some-avail/json2web/blob/main/mostfiles/scricon_startup.nim
In the end of the file the cookie-processing-code is written. I use now only one cookie that i set to disabled after it has been read by the server to prevent it from being reprocessed / rerun. I know i may not win a beauty-contest with it, but for now it is working for me to run nim-server-code from javascript.
Other solutions like compiling to javascript, and apparantly web-sockets maybe better but are future adventures for now. My approach is currently twofold:
Remember i am not a computer-scientist but a hobbyman :-P
But to improve my knowledge i will google on websockets, fetch, endpoints to get ahead...or any other keywords / weblinks if you have extra tips...