I'm using busboy with express.js 4 and node.js to receive via an HTTP POSTa set of field values and an uploaded file from a form in the browser. The file will then be processed (data extracted, new documents created in the database etc.) with the possibility of some of the updates not being successful. What I want to do is update the user what is going on during the processing and then the outcome when all is done.
To do this I want to use HTML5 server sent events. Before some suggests it, I can't use websockets.
When I declare:
var eventSource = new EventSource('/API/upload');
in my browser I see an HTTP GET on the server to this URL. What I want is for eventSource to listen for server sent events from the HTTP POST handler, the route that receives and processes the uploaded metadata and file. My expectation was that in my app.post(... handler I could put:
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive'
});
res.write('\n');
and then push down status updates using:
res.write(message'\n\n');
res.flush(); // I'm using compression
finally terminating the exchange with res.status(200).end(); after all the processing, updating etc. is done. But of course the browser isn't listening for that EventSource, it's listening for one on the GET route
So, how can I:
configure the browser with an EventStream object that doesn't automatically make a GET request when I instantiate it?
and instead listen for events being sent back from the POST event handler on the server?
David. You cannot do it this way. You could use a PUT request to define where the data is going. E.g. PUT /API/upload/1234. Then you could point your event source at the server to get updates.
new EventSource("/API/upload/1234");
That way the server can report on the process of the job.
Related
I have been trying to intercept a server request using Cypress' intercept method.
I have noticed that Cypress can intercept requests made through the front-end/browser, however, the intercept method doesn't work if I make a request directly to the back-end server.
Let me clarify what I mean:
One thing is intercepting a request that the front-end/browser makes to the back-end server.
Another thing is intercepting a call that doesn't use the browser but calls directly the back-end endpoint.
For example:
I can create a user using the front-end interface
or I can create a user calling the back-end endpoint directly (directly calling the server).
Coming back to my question. Is there a way to intercept a call that was made directly to the back-end endpoint?
This is what I have tried so far:
I wrote a regex to intercept api/v0/customers
I then made a request to http://locahost:5440/api/v0/customers (which is the URL of the server)
Finally, I waited for the request to happen
Timeout request using Cypress intercept method
cy.intercept(/^\/api\/v0\/customers\/$/).as('createCustomer');
cy.request(createCustomer(customerData, headers));
cy.wait('#createCustomer').then(({ status, body }) => {
const customerId = body.customer_id;
console.log(body);
expect(status).equal(201);
});
Here's the problem: There was a timeout error.
As you can see in the image, I'm making a request to http://locahost:5440 which is the server URL. NOTE: I made sure the server was up and running.
The regex is also correct and it will match the endpoint http://locahost:5440/api/v0/customers
I suspect that intercept only works for requests being made through the browser. Is this assertion correct? I couldn't find this answer anywhere in the Cypress docs.
Is there a way for me to intercept a call being made directly to a server (not using the browser)?
You don't have to intercept the requests you explicitly make with cypress, just use .then to get the response, like this:
cy.request(createCustomer(customerData, headers)).then((response) => {
const customerId = response.body.customer_id;
console.log(response.body);
expect(response.status).equal(201);
});
Reference: https://docs.cypress.io/api/commands/request#Yields
Consider below scenario:
Client --> Call1 ---> Server
Client <--- Response1 <--- Server
Client processes the response and makes another call
Client --> Call2 ---> Server
Client <--- Response2 <--- Server
Client processes the response and makes another call
Client --> Call3 ---> Server
Client <--- Response3 <--- Server
For above scenario, which tools should I use to make the calls, process the response and measure the response time for the server calls.
Does SOASTA has this capability or any other tool?
What are the things I should keep in mind when doing this?
Without any code changes, you can use Runscope to log and measure API calls. From the Traffic Inspector, click on URL Builder. Enter the URL of the API that you're calling, and you'll see a Runscopified URL below it. Any call that you make to the Runscopified URL will proxy through Runscope to the original destination URL.
In Traffic Inspector, you'll see the HTTP traffic appear, showing you the details of each request (request headers/body/params, response headers/body, status codes, response times, etc.) Again, no need to change any code -- just your request URL, and you'll have full visibility into your API traffic between your client and server.
I am calling json api built using Symfony2 using LAMP stack.
URL for api is like
http://ab.ab.com/new/358342/17/12.948468/77.718571
Response I get back correctly:
{"Result":{"statusCode":1,"statusMsg":"Created Successfully"}}
However http headers contain the information I am logging in server. Example is
-wf-1-1-1-3:185|[{"Type":"INFO","File":"","Line":"","Label":"app"},"Data From Publisher Device Id:358342045834581 Route Id: 17 Lat:12.948468 Lng77.718571 Timestamp:2014-09-18 13:23:20 Data:tstsst|S-1"]|
Above logging info is coming back in Http header of response.
How should I disable the server logging info coming back.
Finally I figured it out.
I was using firephp handler and firephp adds the logging information back in response through http headers.
firephp is useful tool for debugging json apis, however should be disabled in production to avoid revealing sensitive information.
I switched to fingers_crossed handler.
I'm developing a new module in Chromium solution, in which I want to create and send a request to specific server. I've tried to implement this in many way: call Send() method of URL request directly, use URL fetcher, send via IPC route... but no one could be successful.
We have started using Jitterbit. Thanks for the pretty good product.
Can anyone tell me what is the use of HTTP End Point ?
It is used for request or response ?
I believe it is used for only response. When external system send Response to us calling our HTTP end point, we will use the response data and process the operation.
Or else external server will request calling our HTTP End point, we will process the request using many operation .
HTTP endpoint is used to call the Jitterbit Server Endpoint
Let me explain...
Using Jitterbit you have called a webservice (External Source). You got the response same time. Here request and response used same http session.
You are expecting some response from external source after 2 days. You must have some listenerin the Jitterbit server. That listener will kick-in you jitterbit operations.
Ex:- External source will call below URL.
http://www.yourjitterbitsername:46908/endpoint
www.yourjitterbitsername :- Your jitterbit server
46908 : port number
endpoint :- Jitterbit Endpoint.
When external source hit the URL, it executes the corresponding Jitterbit Operation that you have mesnioned in the Http Endpoint synchronously or asynchronously. (You can do in settings)
You can store the request variable in to the jitterbit global variable. Request variable means, the request external source is requesting to the jitterbit server.