· Jan 4, 2021

REST-service how to process Form Data

Hello to all,

I'm trying to post some form data from a form I made in React to the backend of cache fetching a REST-service.
Receiving and processing a JSON-object is no problem but how can I handle Form Data?

The frontend is sending the form as form data and also includes one or more files.

What is the easiest way to process this data in my REST.Broker- class?

Best regards,


Product version: Caché 2017.1
Discussion (6)0
Log in or sign up to continue

Hi Henrique,

I don't have any code for this api yet but I do have one for (for example) JSON:

<Route Url="/newOrder" Method="post" Call="newOrder"/>

ClassMethod newOrder() As %Status {

    S dataToProcess=%request.Content.Read(32000)
    s dataToJSON=$TR(dataToProcess,"'"," ")
    s dataToJSON=$TR(dataToProcess,"""","'")
    s ^simonupload(2)=dataToJSON
    S dataToJSON=##class(Util.JSON).Decode(dataToJSON)
    s ^simonupload(3)=dataToJSON
    s ^simonupload(4)=dataToJSON.GetAt("Opmerkingen")
    s ^simonupload(5)=dataToJSON.GetAt("Bijlagen").GetAt(1)    
    quit $$$OK

This works for receiving JSON.

But I don't know how to do it with Form Data.