notify a server about changes in client side

109 views
Skip to first unread message

RiSi

unread,
Dec 7, 2021, 7:43:52 AM12/7/21
to golang-nuts
Hi, 
having a server written in Go: this server provides an endpoint. 
The client(or consumer) calls this endpoint to notify server about the changes by him. 
My question is: How this server can check the notifications received from client?  
Available implementation approaches are unknown to me. 

Thanks 

Brian Candler

unread,
Dec 7, 2021, 8:10:47 AM12/7/21
to golang-nuts
If the client is notifying the server of changes, then it can just make a HTTP POST to a server endpoint.  Your server just needs to implement that endpoint to receive the POST request.

If the server wants to notify the client of changes in real time, there are various approaches: e.g. Websockets, Server-Sent Events, Long Polling. This is generically known as "Server Push" - see this page in Wikipedia for more references.

RiSi

unread,
Dec 7, 2021, 9:18:33 AM12/7/21
to Brian Candler, golang-nuts
And this POST endpoint should be checked regularly to see when the changes happened? As by each change the server does some action. 
As the server immediately after each POST request from client, need to do some action. How guarantee this in Go?  

Am Di., 7. Dez. 2021 um 14:11 Uhr schrieb Brian Candler <b.ca...@pobox.com>:
If the client is notifying the server of changes, then it can just make a HTTP POST to a server endpoint.  Your server just needs to implement that endpoint to receive the POST request.

If the server wants to notify the client of changes in real time, there are various approaches: e.g. Websockets, Server-Sent Events, Long Polling. This is generically known as "Server Push" - see this page in Wikipedia for more references.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/85e279e0-3a61-4025-b854-3ad31008e04en%40googlegroups.com.

Brian Candler

unread,
Dec 7, 2021, 9:40:55 AM12/7/21
to golang-nuts
> And this POST endpoint should be checked regularly to see when the changes happened? As by each change the server does some action. 

No, that's not how webservers work.

Regardless of the language you are using: you write some code which handles the POST and returns a status code (and possibly empty) body for the response.  In other words, your code runs immediately.  Your code is responsible for processing the content of the request, and generating the response.

RiSi

unread,
Dec 7, 2021, 11:03:29 AM12/7/21
to Brian Candler, golang-nuts
It means in the body of func/handler responsible for this POST Endpoint I pack the necessary actions and each time client calls this endpoint those actions will be also executed. 
Then I do not need to check regularly when called  this endpoint of server. 

Sorry for my naivety

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

Brian Candler

unread,
Dec 7, 2021, 11:47:14 AM12/7/21
to golang-nuts
The handler func is called when the client calls this endpoint, *by definition* of what a handler function is.

Depending on how your application is designed, you can either do work in the handler func, or you can make a note that some work needs to be done (for example, by putting a message in a buffered channel).  If the latter, then a separate part of your application will pick up the task to be done.  If you do it that way, it will be too late to return a success or fail result to the client.

Beware that multiple clients can call your handler func concurrently, in separate but overlapping HTTP requests.  Therefore your code needs to be concurrency-safe.
Reply all
Reply to author
Forward
0 new messages