I have the following setup:
- Macchiato framework for the backend (i.e. ClojureScript on node.js), which models handling on Ring.
- Frontend consisting of a small React App to edit data stored in an atom (tracking various inputs).
I want to make the data stored in that atom persistent by posting it to a handler in my back end. The most straightforward way of doing this would seem to just take the data straight from the atom and do the following:
(http/post "https://post.here.url"
{:edn-params
@my-atom})
However: By default Macchiato requires POST requests to include an anti-forgery token (which I'm currently storing as an attribute to one of my HTML elements; please tell me in case this is bad practice). So I tried the following:
(http/post "https://post.here.url"
{:edn-params
{:data @my-atom
:__anti-forgery-token "SuperSecretToken"}})
This doesn't work, however, since the token is rejected as invalid. The anti-forgery token seems to be processed correctly only if I declare the data as :form-params:
(http/post "https://post.here.url"
{:form-params
{:data (str @my-atom)
:__anti-forgery-token "SuperSecretToken"}})
The method above does work, but ,of course, the MIME type is not set correctly and I have to do some hula-hooping to make the EDN data available on the server side. The approach simply does seem wrong. Is there a way to serialize the EDN data properly and still transmit the anti-forgery token?
I'm still quite new to this stuff, so maybe I'm missing something basic. Am I wrong about the purpose of the anti-forgery token in general? Does it only make sense when transmitting form data (which my data actually is; it's just that posting the atom directly would make reloading the stored data much easier).
Many thanks for any input you may give me!
Oliver