Asynchronous HTTP(S) request in existing loop - http

I want to send a HTTPS request to a server but have a problem figuring out how. The best way for me to do it would be to initiate the request and regularly check back whether it has finished. How can I do this? It is even possible? What are the alternatives?

The best way to make asynchronous I/O is to use tokio.
You can find a example HTTP+TLS in doc : https://tokio.rs/docs/getting-started/tls/

Related

IIS request with quick response but continue to process

I'm working on an API (Pragmatic Rest API or very similar). I would like to know if it is possible to do an API request that will return a quick response (in JSON) and continue to process heavy code in background.
I suppose this is possible by using queue system but I have no idea where to start with this.
You can have your API delegate long running things to another process.
You mentioned queues, that's one way of doing things, all you need really is an application which can execute whatever long running tasks you have.
Let's imagine a simple system that can do this.
Your API receives a request to do something.
Instead of doing this something, the API writes one record into a database with the details of what needs to be done. Another app watches that table, sees a new record, runs the thing, updates the record with the status / result / whatever it needs.
On any requests from now on, the API can check the record and return whatever is there.
This is the simplest thing I can think of. You can easily do other things as well, talk to a queue system, send it data, let something else execute it.
Looking at your comments, what you are suggesting is not really a good way of building APIs. Why do I say this?
Well, let's say that you receive a request, the API starts a work thread and sends back a 200 to the client. Great the client knows work has started and how does it know when that process had ended and how does it receive whatever data it expects back?
Let's go a bit deeper next.
What happens when 1000 clients call that one endpoint and your API is attempting to start 1000 work threads? You've killed your API, no work gets done and no client gets anything.
This is why I suggest to delegate the work to something else, not the API. Let the API do what it does best, run quick things and return results and delegate other things to something else.

How does nginx_redis2_module achieve non-blocking operation?

I need a nginx server that receives HTTP request and sends back response from Redis-store and this should be non-blocking. After Googling and going through forums, i came across the nginx_redis2_module. I tried going through the code but was not able to understand how it works. How have they achieved non-blocking operation? Have they achieved this by adding events to nginx's event loop ? Is there any document or sample code how this is done ?
source : https://github.com/openresty/redis2-nginx-module
The essence of nginx is non blocking modules.
It is complex area.
Here you may found some starting points: how to write Nginx module?
FYI:
When used in conjunction with lua-nginx-module, it is recommended to
use the lua-resty-redis library instead of this module though, because
the former is much more flexible and memory-efficient.

Continue execution asynchronously after return statement

Is there any way to achieve this?
My actual requirement is, I want to return success from my rest service as soon I get the data and perform a basic action on it and then I want to continue some more operations on the data.
I thought of two approaches
Threading - Currently I don't know how I will make it through threading.
Bulk update - I will schedule a task that will do all this processing after may be an hour or so.
But I am not very sure how should I start implementing this.
Any help?
In the context of HTTP we have to remember that once we finish the response, the conversation is over. There is really no way to keep the request alive after you have given the client a response. You would need to implement some worker process that runs outside of HTTP that processes things "queued up" or "triggered" by an HTTP request.

TcpCatcher: send HTTP request from hook

Is it possible, with TcpCatcher to send an HTTP request from a custom hook (a Java class)? I know the GUI let someone edit and resend any given request, but I want this process to be automatic on certain conditions (and log the results, etc.)
So, I know it's possible, but no documentation for it. I'm asking if anyone had done this, or know how to do this? I'm looking at the tcpcatcher.jar file, but many classes are named a.class, b.class, etc. So if the knowledge exists somewhere around this community, it would be great.
TcpCatcher allows you to provide your own java class and calls it when an HTTP packet goes though the proxy.
You can do anything within the hook including sending an other HTTP request (but why would you want do that by the way ?)
Here is an example of a synchronous hook (it allows you to modify the packet on the fly)
http://www.tcpcatcher.org/hook_to_change_html.php
just implement the "modifyPacket" method
If you do not intend to modify the packet on the fly, you can prefer an asynchronous hook.
Here is an example :
http://www.tcpcatcher.org/logging.php

Multiple replies from server for one client request

This may be a dumb question - and the title may need to be improved... I think my requirement is pretty simple: I want to send a request for data from a client to a server program, and the server (not the client) should respond with something like "Received your request - working on it". The client then does other work. Then when the server has obtained the data, it should send an asynchronous message (a popup?) saying "I've got your data; click on ... (presumably a URL) to obtain data". I have been assuming that the server could be written in Java and that client is html and JavaScript. I haven't been able to come up with a clean solution - help would be appreciated.
Try to employ "Websocket Method" by using "SuperWebSocket" for server side, and "WebSocket4Net" for client side. It is working perfectly for my current project.
Most of the work invovles the server being asynchronous. To do this you must
Have an ajax call to the server that starts a job and returns a confirmation the job has been started.
A page on the server that will return whether or not any jobs are complete for a user.
Have an ajax widget on your client side that pings that page on teh server every so often to see if any jobs have been completed. And if so make a pop up.
This is the only way unless you use Flex data services.
Are you trying to do this on the HTTP protocol? It sounds like you're talking about a web application here, but it's not clear from the question. If so, then there are a variety of techniques for accomplishing this using AJAX which collectively go under the name "Comet". Depending on exactly what you're trying to accomplish, a number of different implementation, on both the client and server side, may be appropriate.
for pure java i suggest something like jgroups (client+server are java)
for html, you should use ajax - there you have a timer that checks every X seconds
Nowadays you have an alternative technique to use: Websockets. These are used for server->client communication without polling or ajax-style delayed responses.

Resources