Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use curl commands with ReactJS

Tags:

reactjs

I need to use an API on my website that has its documentation written in CURL commands. Specifically, I would like to know how can I use a command like this on my React app.

curl -H token:"sfg999666t673t7t82" -H "Content-Type: application/json" -H "accept: application/json" -d '{"id":"3970a1b0-6e27-448a-adfc-0083db15b2fb", "tokens":{"design_token1":"Hi","design_token2":"Hello","design_token3":"World","subject_token1":"XYZ"}, "recipient":"[email protected]"}' -X POST "https://domain.provider.com/mas/api/v1/mail/transaction"
like image 307
johnbbab Avatar asked Oct 22 '25 04:10

johnbbab


1 Answers

You can rewrite it to fetch request

fetch("https://domain.provider.com/mas/api/v1/mail/transaction", {
  body: "{\"id\":\"3970a1b0-6e27-448a-adfc-0083db15b2fb\", \"tokens\":{\"design_token1\":\"Hi\",\"design_token2\":\"Hello\",\"design_token3\":\"World\",\"subject_token1\":\"XYZ\"}, \"recipient\":\"[email protected]\"}",
  headers: {
    Accept: "application/json",
    "Content-Type": "application/json",
    Token: "sfg999666t673t7t82"
  },
  method: "POST"
})
like image 72
tagir Avatar answered Oct 23 '25 20:10

tagir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!