@ephaptic/client
v0.1.3
Published
The universal JavaScript client for ephaptic.
Downloads
476
Readme
What is ephaptic?
Nah, just kidding. It's an RPC framework.
ephaptic — Call your backend straight from your frontend. No JSON. No latency. No middleware.
Getting Started
Ephaptic is designed to be invisible. Write a function on the server, call it on the client. No extra boilerplate.
Plus, it's horizontally scalable with Redis (optional), and features extremely low latency thanks to msgpack.
Oh, and the client can also listen to events broadcasted by the server. No, like literally. You just need to add an
eventListener. Did I mention? Events can be sent to specific targets, specific users - not just anyone online.
What are you waiting for? Let's go.
Client:
pip install ephapticServer:
pip install ephaptic[server]from fastapi import FastAPI # or `from quart import Quart`
from ephaptic import Ephaptic
app = FastAPI() # or `app = Quart(__name__)`
ephaptic = Ephaptic.from_app(app) # Finds which framework you're using, and creates an ephaptic server.You can also specify a custom path:
ephaptic = Ephaptic.from_app(app, path="/websocket")And you can even use Redis for horizontal scaling!
ephaptic = Ephaptic.from_app(app, redis_url="redis://my-redis-container:6379/0")Now, how do you expose your function to the frontend?
@ephaptic.expose
async def add(num1, num2):
return num1 + num2Yep, it's really that simple.
But what if your code throws an error? No sweat, it just throws up on the frontend with the same details.
And, want to say something to the frontend?
await ephaptic.to(user1, user2).notification("Hello, world!", priority="high")To use with a framework / Vite:
npm install @ephaptic/clientThen:
import { connect } from "@ephaptic/client";
const client = connect(); // Defaults to `/_ephaptic`.Or, you can use it with a custom URL:
const client = connect({ url: '/ws' });const client = connect({ url: 'wss://my-backend.deployment/ephaptic' });You can even send auth objects to the server for identity loading.
const client = connect({ url: '...', auth: { token: window.localStorage.getItem('jwtToken') } })Or, to use in your browser:
<script type="module">
import { connect } from 'https://cdn.jsdelivr.net/npm/@ephaptic/client@latest/+esm';
const client = connect();
</script>