I wanted to create a bash script that takes an HTML file and sends it to several APIs.
I have a test.html
file with unserialized HTML data like this:
<h2 id="overview">Overview</h2>
<p>Have the source of truth in your own space at <strong>somewhere</strong></p>
<pre>
<code class="lang-javascript">function go() {
console.log('code blocks can be a pain');
}
go();
</code>
</pre>
I need to send the content of the file somehow to an API, like this:
curl --location --request POST 'https://devo.to/api/articles' \
--header 'api-key: askldjfalefjw02ijef02eifj20' \
--header 'Content-Type: application/json' \
--data-raw '{
"article": {
"title": "Blog Article",
"body_markdown": "@test.html",
}
}'
The only way I can think of so far, is to serialize/escape the HTML file, reading it into a variable as a string (like $TEST_HTML=$(cat serialized_test.html
) and then passing it to "body_markdown"
.
Would it be possible to serialize/escape the HTML in one step inside the bash script or is there maybe a better way?