I'm making a POST request to third party API. The POST request returns a success code to the caller and then triggers a background job to run which takes a few seconds to complete. When complete, the API hits the webhook that I provide as a parameter. That is all working fine, but I'm searching for a way for my frontend code that made the original request to be notified once the webhook completes so that I can update my UI accordingly.
I know I can set up a Firebase instance and have a database listener, but I'm searching for a simpler / native way to accomplish this. Any thoughts?
Related
I have been playing around with slack API lately, and I came up with one demo project where I'm having some kind of a chat widget, within that a dropdown on the header populated with channel list(through channels.list API call), by selecting one of it, the channels.history will be called to populate the widget body, and down below on footer a text box and send button to post a new message to slack.. NOW, to keep the widget's body up to date, i)I had to make channels.history rest call periodically(if in case anyone's sending messages on the SLACK app) And Also ii)I had made a rest call when the user sends a message from this widget's text box.
My question now is: How do I skip making this periodic call(because I'm getting 429 warning) instead to have any logic implemented that would trigger the channels.history call only when a new message arrives on slack side and not periodically. or is there any better way to do this?
One way to keep a copy of current messages from a channel up-to-date in a 3rd party app is to use the Events API. You subscribe to the messages event and whenever a new message is posted, Slack will send you a request, which includes the full message. This also works for "complex" messages.
I'm not 100% familiar with the Slack API but I found this: real time messaging APIs.
Since it uses websockets, I assume that you can connect and receive all the emitted messages without having to request periodically for that info. You have to change your app to work with websockets instead for periodic HTTP calls, though.
I am making a call to an API that could take a while to process. I want to show the user a loading bar on the UI.
I put some thought into how I would go about doing this, but I am not sure if it is the correct approach.
User makes expensive call to the API.
API returns an OK that it started processing. Maybe it will also return a threadId or something.
I would then make subsequent calls using that threadId to figure out where it is at in the process to update the loading bar.
I am using an ASP.NET Webforms application that use HttpClient in the code-behind to make calls to an ASP.NET Core Web API. I am not making these calls directly through JavaScript.
If I were to use SignalR would I be adding SignalR to my webforms application or to the WebAPI?
I have a server API which holds session state in the form of managed objects. Unfortunately, there is no way to get references to those managed objects apart from when they are created.
This means there is a need to destroy the objects when the web application is finished with them (otherwise they accumulate on the server and eventually I hit a limit where no more can be created). I have this cleanup code in controller destroy event handlers, but they don't seem to be called when the user, say, refreshes the browser.
What's a proper Angular-ish way to call cleanup code on refresh or close? Is there such a pattern or should the server API be refined to provide a way to get such references? Unfortunately, I'm not in a position to be able to change the server API easily.
Can anybody give me a direction, I want to know how to do auto updating pages like facebook have for new status updates, new likes etc. Ie., if you have a status open in a window and a user click "like", the +1 like automatically appears.
Thanks in advance.
These are done using a PUSH model (subscribe / publish).
The client side first subscribes by issuing an AJAX request. This AJAX request stays alive indefinitely. When the server receives a new like / comment, it publishes this update to the client side thereby ending the AJAX request. The client receives this update and isntantly issues another AJAX request.
It is broadly categorized as Comet.
Once before, I had implemented a Comet web chat application and wrote a somewhat technical write up of what went into it. You can read it here, if interested.
Comet Web Chat Application
Edit:
A heartbeat mechanism (PULL model) is definitely easier to implement, but a PUSH model is far more efficient.
You'll need to use ajax, which is a way to communicate with the database without reloading the web page : you could for example use the
$ajax
function of jQuery framework : here's the doc
im not posting code, but here's a quick overview of what you might wanna do:
have the "like" image
create a script that binds a click handler to the image.
once clicked, the script sends an AJAX request to the server to increment the like
if that request succeeds, return data to the script indicating that it was a success. you might also want to return the number of likes and so on.
once the script knows the success, have it change your "like" image.
as for counting likes, well, its up to you. for a very broad question, this is a broad answer that will point you to the right path.
I am logging some analytics data based on people clicking on my site. When a person clicks on something, it sends a call to my node application via an ajax call, but if what they clicked is an external link, the original request gets cancelled since they leave the site. Is there a good way for node to process the request even after the client has disconnected?
It definitely wouldn't matter if the running process does not need to write things to the response.
Even then, it probably doesn't matter anyway if you do something like
User submits request, you respond "thanx, the job was started". Before you respond, asynchronously execute the job (not hard given that node.js code should be asynchronous to begin with).
Job puts data in some table or file or nosql store.
User can go to a different url to see a list of jobs and their states (started, running, complete) and view results.