Back

[SOLVED] Implementing Server-Side Events in appwrite function.

  • 0
  • Android
  • Functions
  • Self Hosted
sivagowda
13 Jun, 2023, 17:29

I want implement server side events in appwrite. For implementing server side event I need a server which supports this. In express server I can do this by res.write(). But in appwrite function I can't do this as it supports on res.send and res.json. Is there any way to achieve SSE in appwrite function?

TL;DR
To implement server-side events (SSE) in an Appwrite function, you can follow these steps: 1. Add a variable, like `action`, to the data you send to the function. This allows you to create logical routes within the function based on the `action` value. 2. Keep in mind that Appwrite functions use `micro` server behind the scenes. While you can't develop with a full backend mindset, you can treat the function as a direct endpoint for executing your code. 3. Deploy your functions to your Appwrite instance (self-hosted or cloud) and access them using the available SDKs. 4
Binyamin
13 Jun, 2023, 17:34

You want to be able to send events from an Appwrite function? Or you want your Appwrite function to act as a server?

Can you elaborate more about your use case?

sivagowda
13 Jun, 2023, 17:37

My requirement is my appwrite function generate random numbers for 10 senconds and I want to send these random numbers to all the active users.

sivagowda
13 Jun, 2023, 17:38

I want to send randomly generated numbers in real time.

sivagowda
13 Jun, 2023, 17:43

this appwrite function runs once in an hour

Binyamin
13 Jun, 2023, 17:45

Mmm You can try workaround like so.

Function

  1. Create some Appwrite function.
  2. When trigger make the function generate 10 random numbers.
  3. Insert the numbers into a collection

Realtime

  1. Create Realtime channel
  2. subscribe to the channel of the with the previous collection.

Now you'll have a realtime event that will broadcast to all of the subscriptions with 10 random numbers.

sivagowda
13 Jun, 2023, 17:48

OK. this could be done.

sivagowda
13 Jun, 2023, 17:48

How to achieve Appwrite function to act as a server?

Binyamin
13 Jun, 2023, 17:48

In what way?

Binyamin
13 Jun, 2023, 17:49

That you can access it directly?

sivagowda
13 Jun, 2023, 17:50

Appwrite function runs on which server?

Binyamin
13 Jun, 2023, 17:50

To what part you mean?

Binyamin
13 Jun, 2023, 17:51

Appwrite function are scale-to-zero cloud functions.

sivagowda
13 Jun, 2023, 17:51

If I use nodeJS for writing appwrite fuction, does it use express server or http server

Binyamin
13 Jun, 2023, 17:51

That mean, you can deploy your functions to your Appwrite instance (self-hosted or cloud) Then, access your function using one of the available SDKs.

Binyamin
13 Jun, 2023, 17:52

Got you

Binyamin
13 Jun, 2023, 17:52
Binyamin
13 Jun, 2023, 17:53

Appwrite uses micro behind the scenes. But, this part is hidden from you. So, when developing a service using Appwrite function you can't develop it with a full backend mindset, But, think of it as a direct endpoint in which you're executing your code.

Binyamin
13 Jun, 2023, 17:55

That mean, you can't have routes for your function.

But - it's common - to create logical routes. So you can add a variable to data you're sending to the function, Let say action Then inside the function you can check action value and act according to that value.

That will give a logical route.

sivagowda
13 Jun, 2023, 17:58

Cool... Thank you for your time and response

Drake
13 Jun, 2023, 18:05

[SOLVED] Implementing Server-Side Events in appwrite function.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more