Form data handling in IBM API Connect
In this blog, we are going to learn about form data handling in IBM API Connect
Form data refers to the information submitted through an HTML form on a web page. HTML forms are used to collect user input, such as text, selections, checkboxes, and file uploads. When a user fills out a form and submits it, the form data is sent to the server for processing.
Form data consists of key-value pairs, where each input field in the form is associated with a unique name attribute. The value of each input field represents the user’s input or selection. When the form is submitted, the browser collects the values of all the input or selections. When the form is submitted, the browser collects the values of all the input fields and packages them into a format suitable for transmission to the server.
There are two common methods for transmitting form data:
1. GET method: In this method, the form data is appended to the URL as Query parameters. For example, a form submission may result in a URL like: https://example.com/search?query=example&category=books.
2. POST method: In this method, the form data is sent as part of the HTTP request body, separate from the URL. This method is commonly used when submitting sensitive data, such as passwords, or when the form data is large or complex.
How form-data structure is:
First I observed the Form data request in DataPower using Request-type is Non-XML and Response-type is Non-XML in Multi-Protocol Gateway. The Request comes in the form as shown below, with the “Content-Type” header having the value
“multipart/form-data; boundary=————————–769930454610911762373694”.
Body:
“—————————-769930454610911762373694
Content-Disposition: form-data; name=”request”
form info
—————————-769930454610911762373694—“
Here boundary value is changed for every transaction even though whenever we want to add customized value in the form-data Content-Type is required its value is any boundary static also fine.
Need to construct this structure In API Connect:
Prerequisites:
1. Formdata handling backend URL
2. API Manager
3. Postman
Need to create a Parameter named with the request key parameter name.
We need to set the request parameters handling through the “formData” option.
Whenever we need to pass request parameters as it is without any changes simply use the Invoke to call the Backend service.
When we want to do modifications in the Backend request parameters we need to construct the formData using the “Gateway Script” code.
Here main important content is while framing the structure “Content-Type” header and “Content-Disposition”.
Content-Type:
multipart/form-data; boundary=————————–769930454610911762373694
Content-Disposition: form-data; name=
We make this content repeatedly based on the request parameters needed to send to the backend as previously discussed format using “Gateway Script” code.
Testing in Postman:
Here we passed the “form1” only through formData, the IBM API Connect intermittently added another parameter “form2” and the Backend sends back form data value in the form inside as JSON format.