Versions Compared

Key

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

...

Let say that your company has a published API to create a new employee.

The URL looks like this:

     http://yourcompany.com/api/hr/employee

Let's have a look at how you can add the details into the request body. The first example show how to add the details as URL-encoded form values, and the second example adds the content as a JSON string.

Adding the employee details as URL-encoded form values

     Define_Com Class(#XPRIM_HttpRequest) Name(#Req)
#Req.Content.AddUrlEncodedFormValue Name('givenName') Value(#EmpGivenName)
#Req.Content.AddUrlEncodedFormValue Name('lastName') Value(#EmpLastName)​​
#Req.Content.AddUrlEncodedFormValue Name('address') Value(#EmpAddress)

* Execute the request (POST verb)

     #Req.DoPost Url('http://yourcompany.com/api/hr/employee')

Adding the employee details as JSON

     Define_Com Class(#XPRIM_HttpRequest) Name(#Req)
Define_Com Class(#XPRIM_JsonObject) Name(#JsonObject)

* Construct the JSON object

     #JsonObject.InsertString('givenName' #EmpGivenName)
#JsonObject.InsertString('lastName' #EmpLastName)
#JsonObject.InsertString('address' #EmpAddress)

* Add the constructed JSON to the request body

     #Req.Content.AddJsonObject(#JsonObject)

* Execute the request (POST verb)

     #Req.DoPost Url('http://yourcompany.com/api/hr/employee')

Next: Constructing JSON Data for Your Request Body