Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

[ Image Removed |../../index.htm#lansa/webserviceseng01_0385.htm]
You are here:

...

To efficiently construct and add a JSON object or array to your request body, use XPRIM_JsonWriter.
It's essential that you use XPRIM_JsonWriter when your JSON data is big (instead of directly instantiating multiple XPRIM_JsonObject or XPRIM_JsonArray), as XPRIM_JsonWriter is designed to perform better for big data.
Define_Com Class(#XPRIM_HttpRequest) Name(#Req)

  • Create an XPRIM_JsonWriter to efficiently write JSON data
    Define_Com Class(#XPRIM_JsonWriter) Name(#JsonWriter)
  • Set the writer to output the JSON to the HTTP request object
    #JsonWriter.SetOutputToHttpRequest HttpRequest(#Req)
  • Start constructing the object
    #JsonWriter.BeginObject
    #JsonWriter.WriteString Name('givenName') Value(#EmpGivenName)
    #JsonWriter.WriteString Name('lastName') Value(#EmpLastName)
    #JsonWriter.WriteString Name('address') Value(#EmpAddress)
    #JsonWriter.EndObject
  • Execute the request
    #Req.DoPost Url('http://yourcompany.com/api/hr/employee')
    Next: Creating Multiple Part (Multipart) Body
    [ Image Removed |../../index.htm#lansa/webserviceseng01_0385.htm]