Preview:
EMCommonWebAPI  webAPI = EMCommonWebAPI::construct();       
// Prepare the request   
EMWebRequest    webRequest = EMWebRequest::newUrl('https://api.restful-api.dev/objects');
   
// Set the method to use
webRequest.parmMethod('Post');
System.Text.UTF8Encoding encoder;
encoder = new System.Text.UTF8Encoding();

// Initialize the contract to prepare the body
NSHEContract contract = new NSHEContract();
contract.parmName('NShe MacBook Pro 16');
        
NSHEContractData contractData = new  NSHEContractData();
contractData.parmCPUModel('Fast model x');
contractData.parmhardDiskSize('225 GB');
contractData.parmPrice(2000);
contractData.parmYear(2023);
contract.parmData(contractData);

//Convert the data contract to Binary         
System.IO.MemoryStream stream = new System.IO.MemoryStream();
System.Byte[] encodedBytes = encoder.GetBytes(FormJsonSerializer::serializeClass(contract));
stream.Write(encodedBytes, 0, encodedBytes.get_Length());
Binary content = binary::constructFromMemoryStream(stream);
stream.Close();

//Set the body of the request
webRequest.parmContent(content);
webRequest.parmContentType('application/json');

// Get the response by calling the API
EMWebResponse   webresponse = webAPI.getResponse(webRequest);
        
if (webresponse && webresponse.RequestSucceeded())
{
    info ('Succedded');
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter