You can use RestPut in a ViewModel action to send content to an external REST endpoint when that endpoint expects a PUT request.
What RestPut does
RestPut is an Executable Action Language (EAL) operator on selfVM. It sends a PUT request to a target URL. Use it when the receiving service expects a complete representation of a resource or a complete upload, rather than a partial update.
Like the other REST operators, RestPut is available only on the selfVM variable in a ViewModel context. It can send request content, including text and byte-array content, because REST content is supported for POST and PUT requests.
For an overview of calling external REST services from MDriven, see Documentation:Rest Services In MDriven.
Syntax
selfVM.RestPut('targetUrl', '', '')
Replace targetUrl with the URL of the external endpoint. The second and third arguments are the user name and password values; use empty strings when the endpoint does not use these values.
The request content and additional HTTP headers are defined through a ViewModel nesting when required. The nesting name is supplied where the RestPut call supports the optional content-and-header nesting argument. Verify the exact RestPut argument form in your installed MDriven version before adding that optional argument.
Configure the request body and headers
Create a ViewModel nesting for the outgoing request. Its columns determine the content and headers that MDriven sends. The same naming rules apply to REST POST and PUT requests; see Documentation:OCLOperators RestPost for the complete rules and header guidance.
| Column name pattern | Effect for a PUT request | Example use |
|---|---|---|
STRINGCONTENT
|
Sends the column value as string content. Use this as the request body rather than multipart content. Apart from header columns, it should be the only content column. | Send a complete text or XML representation held in a ViewModel variable. |
BYTEARRAYCONTENT
|
Sends the column value as byte-array content. Apart from header columns, it should be the only content column. | Upload one complete binary payload. |
FILENAME_xxx
|
Supplies the file name for byte data in the corresponding xxx column in multipart form-data content.
|
Send a file value in Document with its name in FILENAME_Document.
|
CONTENTTYPE_xxx
|
Supplies the content type for byte data in the corresponding xxx column in multipart form-data content.
|
Set the content type for Document independently of other multipart items.
|
HEADER_xxx
|
Adds xxx as a content header.
|
Add an Authorization content header when the receiving service requires it.
|
HEADERMINUS_xxx
|
Adds a content header after changing underscores in xxx to dashes.
|
Use HEADERMINUS_Content_Type when the header name needs dashes.
|
DEFAULTREQUESTHEADER_xxx
|
Adds xxx as a default request header.
|
Add a request-level header required by the service. |
DEFAULTREQUESTHEADERMINUS_xxx
|
Adds a default request header after changing underscores in xxx to dashes.
|
Use a request header whose name contains dashes. |
By default, content is sent as multipart form-data. To send URL-encoded form values, set HEADERMINUS_Content_Type to application/x-www-form-urlencoded. In that mode, the other columns are sent as string name/value pairs.
Send a complete text representation
Use the following pattern when an endpoint expects one text body.
- In the ViewModel, add a nesting for the outgoing request, for example
Xml. - Add a
STRINGCONTENTcolumn to that nesting. - Set
STRINGCONTENTto the complete text you want to send. For example, set it from a variable that contains XML created by another ViewModel. - Add header columns to the same nesting when the endpoint requires them, such as an authorization header.
- In the action that runs in the ViewModel, call
selfVM.RestPutwith the endpoint URL, credentials when applicable, and the configured content/header nesting as supported by your version.
For example, if vText contains the complete XML to send, the STRINGCONTENT value in the Xml nesting can be populated from vText. The PUT request then uses that value as its body. Do not also add another content column to this nesting; STRINGCONTENT is intended to be the single body-content column, with header columns permitted alongside it.
Send binary or multipart content
Use BYTEARRAYCONTENT when the PUT body is one binary value. Use multipart columns when the endpoint expects form-data with one or more files.
For example, a multipart nesting can contain these columns:
Document— the byte data for the uploaded file.FILENAME_Document— the file name to send forDocument.CONTENTTYPE_Document— the content type to send forDocument.
The Document suffix must match in all three column names. This lets you send a file with its file name and content type as part of the PUT request.
Request-header guidance
Use content-header columns for headers that belong to the request content, and use DEFAULTREQUESTHEADER... columns for request headers. The distinction matters because HTTP request headers and content headers are separate.
Avoid FORCEREQUESTCONTENTTYPE unless the receiving framework cannot handle a GET request without a content type. It works by adding empty content to a GET request and is not appropriate for normal PUT content; PUT already sends content through its configured nesting.
Related REST operators
Use the HTTP method required by the external service:
- RestGet retrieves data from an endpoint.
- RestPost sends content with a POST request and documents the shared content and header conventions.
- RestPut sends content with a PUT request.
