<$button actions=<<fetchDataAPI>>>Fetch data </$button>,
I have tried body='{"foo": [[tiddlername]get[fieldname]]}', this way to send the value of the field to the backend, but I’m receiving it as: Data received: { '{"foo": [': { Prozessbegleiter: { _uvar_local_status: '' } } }.
How can I send the value of a tiddler to the backend?
Can anyone please guide me on this?
The test tiddler contains the following code. I did set some variables tiddlerName and fieldName so it will be easier to change, without the need to change the code.
I am getting the proper value in the tiddler, but if I enclose in the body, I’m sending the data from Tiddly like,
"field:value": ""
I need something like : "field":"value" …meaning that tiddly’s post’s body should send this as a keyvalue pair, but now I’m sending this as , "field:value": "", which is really weird.
I am rephrasing it again, if I send it ,
my key should be "field"
and the value should be "value".
const express = require('express');
const cors = require('cors');
const app = express();
app.use(express.json()); // For parsing application/json
app.use(express.urlencoded({ extended: true })); // For parsing application/x-www-form-urlencoded
// Configure CORS to allow requests from 'https://tiddlywiki.com'
const corsOptions = {
origin: '*',
optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
};
app.use(cors(corsOptions));
// Debugging middleware
app.use((req, res, next) => {
console.log('Headers:', req.headers);
console.log('Body:', req.body);
next();
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log("Server Listening on PORT:", PORT);
});
app.post("/submit", (request, response) => {
const data = request.body; // Capture the data sent in the request body
console.log("Data received:", data);
// Process the data as needed. Here we're just echoing it back.
const responseData = {
message: "Data successfully received.",
receivedData: data,
status: "Processed"
};
const keys = Object.keys(data);
console.log("Keys of the received data:", keys);
// Send the response back to the client
response.json(responseData);
});
There is no js code here. I referred this document and did the tiddly implementation.
My requirement is , if I send the data in the body, it should send as a key value Json pair. Currently in the tiddly implementation, does it have that support yet ?
I can’t assign values to the key.
There is a bug in the documentation of the POST command. But I would need to investigate that further.
Actually there is a problem in the docs. – The header application/json is missing in the “httpbin.org” POST example. So if we add it to the sendmessage it works – also with your app.
But instead of creating a jsonstring with complicated filters, IMO it is easier to send the whole tiddler using the jsontiddler-macro as in the example below.
See the new parameter header-content-type="application/json"
As I wrote a plain text description, what you actually want to achieve would probably be better.
From your initial post, I saw that your JSON data will probably be more complex than “field:values”. So you will definitely have to have a closer look at all the JSON Operators
But as I wrote, the <<jsontiddler macro may be your friend, if you can limit your JSON to a 1 dimentional structure.
Here is the test-tiddler I did use to test the stuff
As I wrote. I would write all fields used for 1 POST request in 1 tiddler and send it with the <<jsontiddler macro. So it will send many fields at once. There are some redundant fields like created, modified and so on. But on the server side it’s easy to remove them.