Waiting Response from Axios From Express js - node.js

i got a issue so i wrote this in my code this is the controller :
on my service i call like sdk to hit external API and i need to get the result of the response from that external API
on my sdk i use Axios like this :
i tried to execute but the response is always return when the status on my API already returned
My question is How to waiting the response from external API like my case ?

Related

Why do we need to add .end() to a response?

Currently building a RESTful API with express on my web server, and some routes like the delete route for a document with mongoose ex. await Note.findByIdAndRemove(request.params.id) response.status(204).end() send response statuses with end()
Why do I need to add the .end()? What in these cases, and why cant one just send response.status(204)
With some responses that return json, the response.status(201).json works fine
Only certain methods with Express or the http interface will send the response. Some methods such as .status() or .append() or .cookie() only set state on the outgoing response that will be used when the response is actually sent - they don't actually send the response itself. So, when using those methods, you have to follow them with some method that actually sends the response such as .end().
In your specific example of:
response.status(204)
You can use the Express version that actually sends the response:
response.sendStatus(204)
If you choose to use .status() instead, then from the Express documentation, you have to follow it with some other method that causes the response to be sent. Here are examples from the Express documentation for .status():
res.status(403).end()
res.status(400).send('Bad Request')
res.status(404).sendFile('/absolute/path/to/404.png')
Since all three of these other methods will cause the response to be sent and when the response goes out, it will pick up the previously set status.

Invalid and trucated data receiving while calling node API get route

While calling Node API get HTTP method data comes in truncated format, incomplete JSON.
But when calling the same api using POSTMAN getting proper response.
If is there any issue regarding NodeAPI please guide how can I solve it?

Azure Api Managment: Function app seems not to be invoked?

I followed this link provided by Microsoft Azure to import a Function App within Api Management. I achieved to import my function and to test it by sending a Http Request (method GET), I got a Http Response with a code 200 OK. However, there is no content (content-length: 0) but it has to return a json string in the body. It seems that the function app is not invoked. This is something I checked when I test individually my function app.
Do you have an idea why there is no content ?
Thanks

Request method not recognized after promisification

I built an API using AWS API Gateway and Lambda, now I am writing end to end tests, I am using Promise from bluebird and request, so I promisified request like this:
Promise.promisifyAll(require('request'));
Promise.promisifyAll(request);
Now when I make requests (POST, PUT, GET), using request.methodAsync, the method is not recognized by the API Gateway !
I launched Jasmine with :
NODE_DEBUG=request jasmine
I can see the method = 'POST' or whatever, but the API still not recognize the method of the requests I am making with the promisified request ! any one run into this situation ?
Hi I'm from the Api Gateway team. As long as the request is sent to a valid resource path / HTTP method pair on a deployed API, Api Gateway will accept it. Please note you'll need to put the stage name as the first path part in the URI (see example in the Api Gateway console on the Stages page).
If you're invoking the right API resource, the issue sounds like a client-side bug.
Jack

POST calls not reaching Controller, failing with 500

In my KrakenJS Node App., I am Trying to test a controller functionality which ultimately does a POST call to a web server.
I am adding a new route in routes/index.js like below so that i can directly test it :
router.post('/testPost', testController.testPostCall);
In this case when i try to call a POST on this URL via Rest Clients ; the call does not even reach the controller & fails with 500 :
(t) URL TestNodeAPP_testPost
(E) LOG INFO
(A) RENDER errors_500 53ms
(T) URL TestNodeAPP_testPost 3391ms
**POST /TestNodeAPP/testPost 500** 3445.722 ms - 2738
But if i change the router method to get like below, the call reaches the controller :
router.get('/testPost', testController.testPostCall);
What needs to be done to make it work for POST call?

Resources