🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Rest Put
This page was created by Stephanie on 2023-04-26. Last edited by Wikiadmin on 2026-07-29.

You can use HTTP PUT with MDriven REST integrations to send data to an external REST service or to handle a PUT request through a REST-exposed ViewModel.

What PUT means

PUT is an HTTP method used to request an update to the resource identified by a URL. A REST service may also use PUT to create that resource when it does not already exist, but this is a rule defined by that service—not a guarantee of PUT itself.

For example, an external API might accept an update at:

https://example.com/users/123

The request body contains the user values to send. The API then returns an HTTP status code that reports whether it accepted or rejected the request.

Use PUT to call an external REST service

In MDriven, RestPut is an OCL REST operator available on selfVM in a ViewModel. Use it when your ViewModel needs to send content to an external REST-based service.

The REST operators—RestGet, RestPost, RestPut, RestDelete, and RestDownload—are available only in ViewModels. They send or retrieve information through REST services outside your application.

Define the request data in a nesting

Provide request data through a ViewModel nesting or class that contains the values to send and, when required, request or content headers. Content can be sent with POST and PUT.

The columns in that nesting control how MDriven builds the PUT request.

Column naming pattern Effect on the PUT request
STRINGCONTENT Sends its value as StringContent. Use it as the single content column, apart from header columns.
BYTEARRAYCONTENT Sends its value as ByteArrayContent. Use it as the single content column, apart from header columns.
FILENAME_xxx Sets the filename for a multipart part named xxx. The corresponding xxx column supplies the byte data.
CONTENTTYPE_xxx Sets the content type for a multipart byte-data part named xxx.
HEADER_xxx Adds xxx and its value as a content header.
HEADERMINUS_xxx Adds a content header after converting underscores in xxx to dashes. For example, HEADERMINUS_Content_Type becomes Content-Type.
DEFAULTREQUESTHEADER_xxx Adds xxx and its value as a default request header.
DEFAULTREQUESTHEADERMINUS_xxx Adds a default request header after converting underscores in xxx to dashes.

By default, MDriven sends request values as MultipartFormDataContent. To send URL-encoded form values instead, set:

HEADERMINUS_Content_Type = 'application/x-www-form-urlencoded'

MDriven then treats the other columns as string name/value pairs and sends them as FormUrlEncodedContent.

Example: choose the appropriate content shape

If an API expects a text body, create a STRINGCONTENT column containing that text and any needed header columns. Do not combine it with other content columns.

If an API expects a multipart file upload, use a byte-data column such as document, then add FILENAME_document for the file name. Add CONTENTTYPE_document when the API requires a specific content type for that file part.

For the full REST-operator rules, including header handling and the RestPut operator details, see Documentation:OCLOperators RestPost.

Receive PUT requests in an MDriven REST service

You can also expose a ViewModel as a REST endpoint and let a client call it with PUT. Enable the ViewModel for REST by setting Eco.RestAllowed to True.

A REST-exposed ViewModel can receive different HTTP verbs, including GET, POST, PUT, PATCH, and DELETE. The ViewModel can use the received verb to apply different rules or actions for each operation.

For example, one ViewModel can accept POST to create data and PUT to run a different update or create action. Make the action available only for the intended verb by using the ViewModel's read-only or disable rules. This lets one endpoint expose verb-specific behaviour without duplicating the ViewModel.

PUT does not impose a fixed create-or-update rule on your model. Define the required action and validation in the ViewModel so that the endpoint performs the operation your API contract requires.

Test the endpoint

  1. Create and deploy the REST-exposed ViewModel.
  2. Use a REST client such as Postman.
  3. Send a PUT request to the ViewModel's REST URL with the request values required by the ViewModel.
  4. Verify the returned HTTP status and JSON response.
  5. Repeat with invalid or incomplete input to confirm that validation and verb-specific rules behave as intended.

Follow HowTos:Expose REST Service to expose the endpoint, and see Documentation:Rest Services In MDriven for the REST service model and URL conventions.

PUT compared with PATCH and POST

Method Typical intent MDriven consideration
PUT Update the resource addressed by the request URL; an API may define it to create when absent. Define the desired create, update, validation, and action rules in the REST-exposed ViewModel.
PATCH Update only the supplied fields on an existing object. See Documentation:OCLOperators RestPatch for PATCH endpoint behaviour and setup.
POST Submit data for server-defined processing, often to create data. See Documentation:Rest Post for action ordering when handling REST POST.

See also