Coingate callback post method data not seen - node.js

I am trying to integrate crypto pay with coingate to my nodejs app but the callback post method has a req.body which is empty. Please do anyone have any idea on how to retrieve the order data so that I can use it for another api call. I have looked on the entire req object and couldn't see the order data.

Related

Why do we add properties to request object?

I can't understand why do we add properties to request object?
As I know, the request object comes from the front end side and if any information is needed or they have, the frontend side should attach it to the request object and send it to backend side like a cookie or JWT token, etc.
And after we got that information in the backend side we can add/update more properties to the response object, like new JWT token, new session ID, etc.
But I see in backend codes, they also add properties to request object and this is vague to me. I don't know why the backend side should add something to the request? Maybe because of the internal transactions between the different middleware this happens? I mean middleware1 adds something to the request object and sends it to the middleware2 in backend side?
For example I can't understand why do we add something to req.session not res.session? Because as I understand this data should be passed to the frontend side to be added into their next request.
But if there is any other reason for adding properties to req object instead of the res object, please let me know?
Mutating the request object by adding additional properties is the primary method of passing additional data between middlewares within Express. Since the request and response are passed to every middleware, this is the only chain that gives you continuity between middlewares.
(You will also see some passed on the response object as well, but in general it's most common to see it on req).
Note that you need to avoid collisions with Express's properties and methods as well as the underlying connection objects from Node.

At what point are request and response objects populated in express app

I’m always coding backend api’s and I don’t really get how express does its bidding with my code. I know what the request and response objects offer, I just don’t understand how they come to be.
This simplified code for instance:
exports.getBlurts = function() {
return function(req, res) {
// build query…
qry.exec(function(err, results) {
res.json(results);
}
});
}
}
Then I’d call in one of my routes:
app.get('/getblurts/, middleware.requireUser, routes.api.blurtapi.getBlurts());
I get that the function is called upon the route request. It’s very abstract to me though and I don’t understand the when, where, or how as it pertains to the req\res params being injected.
For instance. I use a CMS that modifies the request object by adding a user property, which is then available globally on all requests made whether ajax or otherwise, making it easy at all times to determine if a user is logged in.
Are the req and res objects just pre-cooked by express but allow freedom for them to be modified to your needs? When are they actually 'built'
At its heart express is actually using node's default http-module and passing the express-application as a callback to the http.createServer-function. The request and response objects are populated at that point, i.e. from node itself for every incoming connection. See the nodeJS documentation for more details regarding node's http-module and what req/res are.
You might want to check out express' source code which shows how the express application is passed as a callback to http.createServer.
https://github.com/expressjs/express/blob/master/lib/request.js and https://github.com/expressjs/express/blob/master/lib/response.js show how node's request/response are extended by express specific functions.

POST Method in Feathers Example

Can someone explain, how I make a POST method using Feathers and test it in postman. I notice that there are two parameters, "data" and "params". What are their differences? Can someone give me a complete example how to create POST method in feathers and test it in postman?
Thanks
The data is the actual data passed to the service method, ex: a form data. and the params contains the provider (i.e REST, Socket.io or Primus), connection details, authenticated user details and other info related to that service.
For post method you can use the create(data, params) method of the service that you are calling and do your post activity there like creating records like below.
app.use('/messages', {
messages: [],
create(data, params) {
this.messages.push(data);
// Your post activity here
return Promise.resolve(data);
}
});
And in postman use can use the URL http://localhost:3030/messages and in the request body provide the JSON you want to pass as a data to the POST method
ref: https://docs.feathersjs.com/api/services.html

How to get post body with Koa-router-forward-request?

I have the koa-router-forward-request set up. I make an axios call to it and that call is forwarded onto an API. I can do get requests and retrieve the information. I can't get post requests working. I want to forward the post request body from the original axios call onto the API how do I do that?
I have const composeRequest = body;
and in the request I have composeBody: composeRequest as an attribute but that does not seem to be working.
This is super late but I think what you are looking for is maybe to 1. ensure you are using bodyParser() i.e. router.use(bodyParser()) and 2. when hitting the Koa route pull any params you pass via Axios by ctx.request.body, all params should be stored in there to pull out.

How to send a http response using koajs

I'm trying to validate a webhook via facebook. So facebook hits my url my-url/facebook/receive within my route in nodejs i'd do res.send(req.query['hub.challenge']); to send an http response.
I'm using KoaJS. From what i understand, Koajs merges the request and response object into ctx but when reading through the docs I can't find anything along the lines of ctx.send or similar to send a http response.
Can anyone give me some direction or links.
Thanks.
To send the body of a response, you can simply do ctx.response.body = 'Hello'. There are many aliases attached to ctx, so you don't necessarily have to reference the response or request yourself. Doing ctx.body = 'Hello' would be the same as the code above.
If you wanted to set headers, you would use the ctx.set() method. For example: ctx.set('Content-Type', 'text/plain').
To access the query parameters, you would use ctx.request.query['some-key'] (or simply the alias ctx.query['some-key']).
All of the different request/response methods are documented pretty well at the Koa website along with a list of aliases attached to ctx. I highly recommend you give it a read.

Resources