Communication with server and client <nextjs>

i have a webhook which calls nextjs api, can that api call do something which triggers an action on
17 Replies
albatroz
albatroz4w ago
@nyx (Rustular DevRel) hey, could you help me understand the flow?
Neto
Neto4w ago
are you using vercel?
albatroz
albatroz4w ago
yes
Neto
Neto4w ago
then no you will need pooling
albatroz
albatroz4w ago
ohh
Neto
Neto4w ago
or use a external service for sockets
albatroz
albatroz4w ago
so the platform's webhook will call the api of nextjs, and not sure after that
Neto
Neto4w ago
the base line is the following
No description
Neto
Neto4w ago
WS can be pusher or socketi, as a example
albatroz
albatroz4w ago
do nextjs has websocket ?
Neto
Neto4w ago
vercel runs on lambdas/workerd so no websockets from nextjs without running on a server 100% pusher is the easiest thing
albatroz
albatroz4w ago
GitHub
GitHub - pusher/docs: The all new Pusher docs, powered by @11ty and...
The all new Pusher docs, powered by @11ty and @vercel - pusher/docs
Neto
Neto4w ago
yeah
// on the API route that receives the webhook request
pusher.trigger('my-channel', 'my-event', {
"message": "hello world"
});

// on the client side
// connect to pusher and listen to events
// on the API route that receives the webhook request
pusher.trigger('my-channel', 'my-event', {
"message": "hello world"
});

// on the client side
// connect to pusher and listen to events
albatroz
albatroz4w ago
understood Thanks
Neto
Neto4w ago
np
Bohdan
Bohdan4w ago
if this webhook happens as a consequence of a client side action, you could do polling i.e. make a request to the backend every N seconds to check for your api action
Bohdan
Bohdan4w ago
here's an in-depth explanation of the polling approach https://youtu.be/ZPh2Hapjd64?si=pAKZhQnA8e2_ZYm1
Web Dev Cody
YouTube
This is why you'll need polling in your web applications
give Hosna a follow: https://www.youtube.com/@hqasmei --- my courses --- 📘 T3 Stack Tutorial: https://1017897100294.gumroad.com/l/jipjfm --- my products --- 📖 ProjectPlannerAI: https://projectplannerai.com 🤖 IconGeneratorAI: https://icongeneratorai.com/ --- useful links --- 💬 Discord: https://discord.gg/4kGbBaa 🔔 Newsletter: https://newslette...