Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Variant vJson
Handle hoJson
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
Integer iItemId
String sName
Integer iPrice
String sDescription
Integer iOrderId
String sArrivalDate
String sOrderDate
Integer iOrderTotal
String sAddress
Integer i
Integer iCount_i
String sTemp1
Boolean bTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "address": "<string>",
// "item": {
// "itemId": "<integer>",
// "name": "<string>",
// "price": "<integer>",
// "description": "<string>"
// }
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "address" "<string>" To iSuccess
Get ComUpdateString Of hoJson "item.itemId" "<integer>" To iSuccess
Get ComUpdateString Of hoJson "item.name" "<string>" To iSuccess
Get ComUpdateString Of hoJson "item.price" "<integer>" To iSuccess
Get ComUpdateString Of hoJson "item.description" "<string>" To iSuccess
Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
Get pvComObject of hoJson to vJson
Get ComPostJson3 Of hoHttp "https://api.simplekart.com/orders" "application/json" vJson To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJResp To False
Showln "Response Body:"
Get ComEmit Of hoJResp To sTemp1
Showln sTemp1
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Send Destroy of hoResp
Procedure_Return
End
Send Destroy of hoResp
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "orderId": 674,
// "items": [
// {
// "itemId": 1657,
// "name": "Smart WiFi Router",
// "price": 2096,
// "description": "Wifi router/wireless router. One of routers for wireless internet, wireless routers for home. Dual band router and gigabit router. Ideal as internet router also gaming router. Long range coverage with high speed. Compatible with all 802.11ac devices and below. 5ghz router/5g router Frequency Range: 2.4GHz and 5GHz; Interface Available: 4 x 10/100/1000Mbps LAN Ports, 1 10/100/1000Mbps WAN Port, 1 USB 2.0 Ports; Protocols Supported: Supports IPv4 and IPv6; System Requirement: Microsoft Windows 98SE NT 2000 XP Vista, or Windows 7 Windows 8/8.1/10, MAC OS NetWare UNIX or Linux; Wireless Standards: IEEE 802.11ac/n/a 5GHz, IEEE 802.11b/g/n 2.4GH"
// }
// ],
// "arrivalDate": "2020-3-04T13:07:45.962Z",
// "orderDate": "2020-03-06T19:27:26.733Z",
// "orderTotal": 2096,
// "address": "95 Tarkiln Hill St.Laurel, MD 20707"
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
Get ComIntOf Of hoJResp "orderId" To iOrderId
Get ComStringOf Of hoJResp "arrivalDate" To sArrivalDate
Get ComStringOf Of hoJResp "orderDate" To sOrderDate
Get ComIntOf Of hoJResp "orderTotal" To iOrderTotal
Get ComStringOf Of hoJResp "address" To sAddress
Move 0 To i
Get ComSizeOfArray Of hoJResp "items" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComIntOf Of hoJResp "items[i].itemId" To iItemId
Get ComStringOf Of hoJResp "items[i].name" To sName
Get ComIntOf Of hoJResp "items[i].price" To iPrice
Get ComStringOf Of hoJResp "items[i].description" To sDescription
Move (i + 1) To i
Loop
End_Procedure
Curl Command
curl -X POST
-H "Content-Type: application/json"
-d '{
"address": "<string>",
"item": {
"itemId": "<integer>",
"name": "<string>",
"price": "<integer>",
"description": "<string>"
}
}'
https://api.simplekart.com/orders
Postman Collection Item JSON
{
"name": "Post order details to the database",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"address\": \"<string>\",\n \"item\": {\n \"itemId\": \"<integer>\",\n \"name\": \"<string>\",\n \"price\": \"<integer>\",\n \"description\": \"<string>\"\n }\n}"
},
"url": {
"raw": "{{baseUrl}}/orders",
"host": [
"{{baseUrl}}"
],
"path": [
"orders"
]
},
"description": "Post item order to orders database"
},
"response": [
{
"name": "OK - Order created",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"items\": [\n {\n \"itemId\": 1657,\n \"name\": \"Smart WiFi Router\",\n \"price\": 2096,\n \"description\": \"Wifi router/wireless router. One of routers for wireless internet, wireless routers for home. Dual band router and gigabit router. Ideal as internet router also gaming router. Long range coverage with high speed. Compatible with all 802.11ac devices and below. 5ghz router/5g router Frequency Range: 2.4GHz and 5GHz; Interface Available: 4 x 10/100/1000Mbps LAN Ports, 1 10/100/1000Mbps WAN Port, 1 USB 2.0 Ports; Protocols Supported: Supports IPv4 and IPv6; System Requirement: Microsoft Windows 98SE NT 2000 XP Vista, or Windows 7 Windows 8/8.1/10, MAC OS NetWare UNIX or Linux; Wireless Standards: IEEE 802.11ac/n/a 5GHz, IEEE 802.11b/g/n 2.4GH\"\n }\n ],\n \"address\": \"95 Tarkiln Hill St.Laurel, MD 20707\"\n}"
},
"url": {
"raw": "{{baseUrl}}/orders",
"host": [
"{{baseUrl}}"
],
"path": [
"orders"
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"orderId\": 674,\n \"items\": [\n {\n \"itemId\": 1657,\n \"name\": \"Smart WiFi Router\",\n \"price\": 2096,\n \"description\": \"Wifi router/wireless router. One of routers for wireless internet, wireless routers for home. Dual band router and gigabit router. Ideal as internet router also gaming router. Long range coverage with high speed. Compatible with all 802.11ac devices and below. 5ghz router/5g router Frequency Range: 2.4GHz and 5GHz; Interface Available: 4 x 10/100/1000Mbps LAN Ports, 1 10/100/1000Mbps WAN Port, 1 USB 2.0 Ports; Protocols Supported: Supports IPv4 and IPv6; System Requirement: Microsoft Windows 98SE NT 2000 XP Vista, or Windows 7 Windows 8/8.1/10, MAC OS NetWare UNIX or Linux; Wireless Standards: IEEE 802.11ac/n/a 5GHz, IEEE 802.11b/g/n 2.4GH\"\n }\n ],\n \"arrivalDate\": \"2020-3-04T13:07:45.962Z\",\n \"orderDate\": \"2020-03-06T19:27:26.733Z\",\n \"orderTotal\": 2096,\n \"address\": \"95 Tarkiln Hill St.Laurel, MD 20707\"\n}"
}
]
}