What if you could call your server functions directly from your client?
gravity.digitak.dev
gravity.digitak.dev
bus.method(“auth.login, (params, client) => {…})
bus.on(“auth.logged_in”, (params, client) => {…})
bus.call(“auth.login”, …params)
bus.notify(“auth.logged_in”, …params)
You can also call/notify in every direction (via `client` handle to one, via `bus` handle to all clients). Works through web sockets.If you don’t mind, I’d suggest considering notification mode, which doesn’t require awaits, and uses navigator.sendBeacon() under the hood. For events that do not assume any answer by design, like “user moved to section X”.
Also, does it by chance have call/result logging?
I would also like to think about how to have the same « safe » communication system for sockets. It’s more complicated.
What do you mean by call/result logging?
Just seeing calls with arguments and return values in some sort of log[file]. I like to see the traffic between ends while debugging. Libraries usually provide a logger callback in initial options, like this:
new Foo({
…,
log: (level, …values) => {…}
})
I think the last time I browsed Gravity manual, it had some sort of “beforeCall” event where it’s possible to log without a special callback.I found myself thinking "Too bad Next.js does API handling itself, so I won't be able to use this tool easily", but then I saw that they already took care of that: https://gravity.digitak.dev/docs/frameworks/next .
So I might actually end up using this. Thanks for sharing it here!
I just released a fix for React/Next stores, so make sure you are using the latest Gravity version ;)
Gravity is a new way to communicate between server and client. No more query language to learn. No more unsafe REST apis. Just 100% end-to-end typesafe good old functions.
It can integrate with modern front-end frameworks like React, Svelte, Solid and Vue.
I’m already using it on the SAAS I’m working on full-time, hope you will like it as much as I do