POST Json API by PHP
thibault-chausson opened this issue · comments
Hello,
I’m looking for a method to generate LaTex files by using a docker.
I found a solution proposed by latex-online on github but I encountered difficulties with the sending of the dependencies. An exemple of a dependency I’m trying to send is an image that is included in a .tex file.
Does your solution allow the sending of curl from php (see the following exemple for the code).
//https://www.codexworld.com/post-receive-json-data-using-php-curl/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "POST https://latex.ytotech.com/builds/sync");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, "Content-Type:application/json");
$datas = {
"compiler": "lualatex",
"resources": [
{
"main": true,
"content": "\\documentclass{article}\n \\usepackage{graphicx}\n \\begin{document}\n Hello World\\\\\n \\includegraphics[height=2cm,width=7cm,keepaspectratio=true]{logo.png}\n \\include{page2}\n \\end{document}"
},
{
"path": "logo.png",
"url": "https://www.ytotech.com/images/ytotech_logo.png"
},
{
"path": "page2.tex",
"file": "VGhpcyBpcyB0aGUgc2Vjb25kIHBhZ2UsIHdoaWNoIHdhcyBwYXNzZWQgYXMgYSBiYXNlNjQgZW5jb2RlZCBmaWxl"
}
]
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $datas);
$response = curl_exec($ch);
curl_close($ch);
Thank you,
Yes, Curl from PHP would do, as any HTTP client.
Have you succeeded to compile a payload?
You will need to read and convert your dependency file content to base64, to include it in a entry with a property file
:
{
"resources": [
{
"main": true,
"content": "\\documentclass{article} ...."
},
{
"path": "image.png",
"file": "<base64 of image>"
}
]
}
Relevant PHP docs:
Thank you for the information, I'm gonna try it now.
@thibault-chausson have you done what you wanted?
I close but you can ask again for issues or just guidance. (examples could serve others)