Converting a cURL script into a SIL script
Converting a cURL script into a SIL script can be time-consuming. Make the conversion easy by following these steps!
Instructions
For this example, I will be building off this page, “Running Scripts Via REST”.
Import the curl script into Postman by following these instructions.
In the right-hand side of Postman, click on the “</>” symbol to see the code converter.
Select the language you would like to convert. “Java - Unirest” is the easiest because it parses the headers in a way that is easiest to refactor into SIL code.
Create headers based on the Java code. The following copied from the Java code…
.header("Accept", "application/json") .header("Content-Type", "application/json") .header("Authorization", "Basic PFVTRVJOQU1FOlBBU1NXT1JEPg==")
…can be converted into:
HttpRequest request; request.headers += httpCreateHeader("Accept", "application/json"); request.headers += httpCreateHeader("Content-Type", "application/json"); request.headers += httpCreateHeader("Authorization", "Basic PFVTRVJOQU1FOlBBU1NXT1JEPg==");
Now set a string variable using the body. You should be able to paste the string without modification.
string payload = "{ \n \"source\": {\n \"type\": \"FILE\", \"code\": \"<PATH/TO/FILE.SIL>\"\n },\n \"args\": [<\"ARGUMENTS\", \"FOR\", \"ARGV\", \"GO HERE\">]\n }";
Lastly, convert the Java post() method to httpPost():
Final Script
Now that we have all the basic building blocks for a script, put them all together and add some error message handling at the end of the script. If you would like to change up the values passed by the payload, see this documentation on working with JSON.
Related articles
Filter by label
There are no items with the selected labels at this time.