Hello everyone,
I’m trying to set up some simple API for my application.
I followed this tutorial with some modifications (I am not using Iron Router).
As of now, the GET request works flawlessly, but the POST is not passing the correct body in the request. Actually, it’s not really passing anything.
I’m using Meteor’s HTTP package to test the calls.
const data = {
params: {
url: "http://www.example.com/"
}
};
HTTP.call("POST", "http://localhost:3000/api/v1/link", data, function(
error,
response
) {
if (error) {
console.log(error);
} else {
console.log("Response:", response.message);
}
});
I tried changing “params” to “data” as someone suggested, but with no luck.
In my main.js server file I am using WebApp as a middleware,
import { Meteor } from "meteor/meteor";
import { WebApp } from "meteor/webapp";
import { API } from "../imports/api/links";
Meteor.startup(() => {
WebApp.connectHandlers.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
API.handleRequest(res, req);
});
});
Here basically doing something like
console.log(req.body);
gives an undefined value.
There’s no need to talk about the API file because req.body is already undefined before being passed to the API file.
Could you help me?
Thank you!