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
albatroz2mo ago
@nyx (Rustular DevRel) hey, could you help me understand the flow?
Neto
Neto2mo ago
are you using vercel?
albatroz
albatroz2mo ago
yes
Neto
Neto2mo ago
then no you will need pooling
albatroz
albatroz2mo ago
ohh
Neto
Neto2mo ago
or use a external service for sockets
albatroz
albatroz2mo ago
so the platform's webhook will call the api of nextjs, and not sure after that
Neto
Neto2mo ago
the base line is the following
No description
Neto
Neto2mo ago
WS can be pusher or socketi, as a example
albatroz
albatroz2mo ago
do nextjs has websocket ?
Neto
Neto2mo ago
vercel runs on lambdas/workerd so no websockets from nextjs without running on a server 100% pusher is the easiest thing
albatroz
albatroz2mo 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
Neto2mo 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
albatroz2mo ago
understood Thanks
Neto
Neto2mo ago
np
Bohdan
Bohdan2mo 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
Bohdan2mo 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...