Windward DocumentationWindward Core.NET RESTful Engine User Manual ReferenceRESTful Engine API Tutorial: Constructing Simple Request Bodies Using Base64 Encoded Data

RESTful Engine API Tutorial: Constructing Simple Request Bodies Using Base64 Encoded Data

Now that you have sent your first template for processing and retrieved the completed document, we will step through putting together a request body with another template and data source so you can feel more comfortable doing this for your own templates and data sources later. In this tutorial, we will use base64 encoded data to post our template.

Just for your reference, here is a template version of the JSON request body we will be using:

{  
   "OutputFormat": "string",  
   "Data": "string",  
   "ConnectionString": "string",  
   "Datasources": [    
       {      
           "Name": "string",      
           "Type": "string",    
           "ConnectionString": "string",      
           "Data": "string"   
       }  ],  
   "TrackImports": false,  
   "TrackErrors": 3
}

Clicking on the file above will open the file in your browser. Make sure to save the file to your machine (CTRL+S).

Note that the templated request body above does not contain all possible values and configurations that our engine offers, but the basic values you will need to run a simple template with one data source

For this tutorial, we will be using the following template and data source:

Clicking on the file above will open the file in your browser. Make sure to save the file to your machine as (CTRL+S).

Request Body Using Base64

Download the provided "templatedRequestBody.json" and open it in a text editor

   - Any text editor will work but in the long term we recommend using Visual Studio Code as it is a         lightweight editor that will help with the formatting of the JSON in the request body

Also download the attached template and data file ("Manufacturing.docx" and "Manufacturing.xml" respectively"


We will now begin replacing the "string" placeholders in the request body with the values we want:

1. First we will set the output format. The RESTful engine supports a handful file formats that you can choose to output in. For this tutorial we will use PDF. So in the request body set the "OutputFormat" value to "pdf". For a full list of output formats, check out the example request body here.

2. Next we have the "Data" entry. Here we will pass in our template data as a base64 encoded string. To do so we will use the following online encoder

  • When you open the online encoder, under "Option 2" click "Choose File" button and select the template file you downloaded earlier, then click encode.
  • Then copy the entire base64 string and paste it as the value of the "Data" entry. Make sure to encompass the base64 string in quotations (represent it as a string)
  • These strings can be long so make sure you get every character in the string when copying
  • Note that you can use any base64 encoder you want

3. For this part of the tutorial we will set "ConnectionString" as null. The reason for this is that we will be providing the template via a base64 encoded string. For our RESTful engine, you either pass the data in as a connection string, or as a base64 encoded string (as we are in this part of the tutorial). So since we will be populating the "Data" entry, we will set the "ConnectionString" entry to null.


Now we will set our "Datasources", which is a list of data sources your template needs. So if you have multiple data sources used in your template you will have multiple entries under the "Datasources" entry. For this tutorial, however, our template only requires one data source, so we will only have one entry.


4. For "Name", we will enter "MANF_DATA_2009".

5. We offer a handful of data source types that we support for our RESTful engine, for this tutorial we are using an XML data source. So set "Type" to "xml". For a full list of data source types, check out the example request body here.

6.  Similar to template data, since we are using the "Data" entry with the data source data passed as a base64 encoded string, we will set the "ConnectionString" entry to null.

7. Next we have the "Data" entry. Here we will pass in our data source data as a base64 encoded string. To do so we will use the following online encoder

  • When you open the online encoder, under "Option 2" click "Choose File" button and select the XML data source file you downloaded earlier then click encode.
  • Then copy the entire base64 string and paste it as the value of the "Data" entry. Make sure to encompass the base64 string in quotations (represent it as a string)
  • These strings can be long so make sure you get every character in the string when copying

Note: The data source name is specified during the creation of the template. So when you create your own template and connect a data source to it, you will specify the name then and use that name here when construction your request body.

You have now completed constructing the request body for this template using connection strings. You can test it in SwaggerHub by following the steps for posting and retrieving documents in the previous tutorial. However, instead of executing the provided sample request body provided in SwaggerHub, we will replace it with the body we just created:

5. We offer a handful of data source types that we support for our RESTful engine, for this tutorial we are using an XML data source. So set "Type" to "xml". For a full list of datasources, check out the example request body here.

6. Next we will set the connection string. For "ConnectionString", set "https://wnd-unittest-resources.s3.amazonaws.com/Test/Manufacturing.xml". Similar to the template data, since we are providing a connection string for our data, we will not need to populate the "Data" entry and will set it to null in the next step. Only use "Data" if you are not using the "ConnectionString".


7. As explained in step 6, we will set "Data" to null.


You have now completed constructing the request body for this template using connection strings. You can test it in SwaggerHub by following the steps for posting and retrieving documents in the previous tutorial. However, instead of executing the provided sample request body provided in SwaggerHub, we will replace it with the body we just created:

  1.  Go through the same steps as in the previous tutorial for using the RESTful engine on SwaggerHub.
  2. When you get to "step 4" in the tutorial, click "Try it out", then paste your request body in:

Now you can follow the rest of the steps in the other tutorial to check the status of the document, and then get the document once it is complete.

Next Steps

Now that you have constructed your own RESTful request body using connection strings, and were able to successfully post it and later on retrieve the processed document, consider constructing a request body using connection strings, or setting up your own RESTful engine to do some more of your own testing. If this is something you wish to do, here are some relevant links:

0 Comments

Add your comment

E-Mail me when someone replies to this comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.