GetNetworkRoutes Foxpro Example
LOCAL loRest
LOCAL lnSuccess
LOCAL loAuthAws
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJResp
LOCAL lcDestinationCidrBlock
LOCAL lcPrefixListId
LOCAL lcState
LOCAL lcV_Type
LOCAL j
LOCAL lnCount_j
LOCAL lcCoreNetworkAttachmentId
LOCAL lcResourceId
LOCAL lcResourceType
LOCAL lcTransitGatewayAttachmentId
LOCAL lcCoreNetworkId
LOCAL lcEdgeLocation
LOCAL lcSegmentName
LOCAL lcRouteTableArn
LOCAL lnRouteTableTimestamp
LOCAL lcRouteTableType
LOCAL i
LOCAL lnCount_i
* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loRest = CreateObject('Chilkat_9_5_0.Rest')
loAuthAws = CreateObject('Chilkat_9_5_0.AuthAws')
loAuthAws.AccessKey = "AWS_ACCESS_KEY"
loAuthAws.SecretKey = "AWS_SECRET_KEY"
* Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
loAuthAws.Region = "us-west-2"
loAuthAws.ServiceName = "networkmanager"
* SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
loRest.SetAuthAws(loAuthAws)
* URL: https://networkmanager.us-west-2.amazonaws.com/
* Use the same region as specified above.
lnSuccess = loRest.Connect("networkmanager.us-west-2.amazonaws.com",443,1,1)
IF (lnSuccess <> 1) THEN
? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
? loRest.LastErrorText
RELEASE loRest
RELEASE loAuthAws
CANCEL
ENDIF
* The following code creates the JSON request body.
* The JSON created by this code is shown below.
* Use this online tool to generate code from sample JSON:
* Generate Code to Create JSON
loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.UpdateString("DestinationFilters.string[0]","string")
loJson.UpdateString("ExactCidrMatches[0]","string")
loJson.UpdateString("LongestPrefixMatches[0]","string")
loJson.UpdateString("PrefixListIds[0]","string")
loJson.UpdateString("RouteTableIdentifier.CoreNetworkSegmentEdge.CoreNetworkId","string")
loJson.UpdateString("RouteTableIdentifier.CoreNetworkSegmentEdge.EdgeLocation","string")
loJson.UpdateString("RouteTableIdentifier.CoreNetworkSegmentEdge.SegmentName","string")
loJson.UpdateString("RouteTableIdentifier.TransitGatewayRouteTableArn","string")
loJson.UpdateString("States[0]","string")
loJson.UpdateString("SubnetOfMatches[0]","string")
loJson.UpdateString("SupernetOfMatches[0]","string")
loJson.UpdateString("Types[0]","string")
* The JSON request body created by the above code:
* {
* "DestinationFilters": {
* "string": [
* "string"
* ]
* },
* "ExactCidrMatches": [
* "string"
* ],
* "LongestPrefixMatches": [
* "string"
* ],
* "PrefixListIds": [
* "string"
* ],
* "RouteTableIdentifier": {
* "CoreNetworkSegmentEdge": {
* "CoreNetworkId": "string",
* "EdgeLocation": "string",
* "SegmentName": "string"
* },
* "TransitGatewayRouteTableArn": "string"
* },
* "States": [
* "string"
* ],
* "SubnetOfMatches": [
* "string"
* ],
* "SupernetOfMatches": [
* "string"
* ],
* "Types": [
* "string"
* ]
* }
loRest.AddHeader("Content-Type","application/x-amz-json-1.1")
loRest.AddHeader("X-Amz-Target","GetNetworkRoutes")
loSbRequestBody = CreateObject('Chilkat_9_5_0.StringBuilder')
loJson.EmitSb(loSbRequestBody)
loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/global-networks/{globalNetworkId}/network-routes",loSbRequestBody,loSbResponseBody)
IF (lnSuccess <> 1) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loAuthAws
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody
CANCEL
ENDIF
lnRespStatusCode = loRest.ResponseStatusCode
? "response status code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode <> 200) THEN
? "Response Header:"
? loRest.ResponseHeader
? "Response Body:"
? loSbResponseBody.GetAsString()
RELEASE loRest
RELEASE loAuthAws
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody
CANCEL
ENDIF
loJResp = CreateObject('Chilkat_9_5_0.JsonObject')
loJResp.LoadSb(loSbResponseBody)
* The following code parses the JSON response.
* A sample JSON response is shown below the sample code.
* Use this online tool to generate parsing code from sample JSON:
* Generate Parsing Code from JSON
lcCoreNetworkId = loJResp.StringOf("CoreNetworkSegmentEdge.CoreNetworkId")
lcEdgeLocation = loJResp.StringOf("CoreNetworkSegmentEdge.EdgeLocation")
lcSegmentName = loJResp.StringOf("CoreNetworkSegmentEdge.SegmentName")
lcRouteTableArn = loJResp.StringOf("RouteTableArn")
lnRouteTableTimestamp = loJResp.IntOf("RouteTableTimestamp")
lcRouteTableType = loJResp.StringOf("RouteTableType")
i = 0
lnCount_i = loJResp.SizeOfArray("NetworkRoutes")
DO WHILE i < lnCount_i
loJResp.I = i
lcDestinationCidrBlock = loJResp.StringOf("NetworkRoutes[i].DestinationCidrBlock")
lcPrefixListId = loJResp.StringOf("NetworkRoutes[i].PrefixListId")
lcState = loJResp.StringOf("NetworkRoutes[i].State")
lcV_Type = loJResp.StringOf("NetworkRoutes[i].Type")
j = 0
lnCount_j = loJResp.SizeOfArray("NetworkRoutes[i].Destinations")
DO WHILE j < lnCount_j
loJResp.J = j
lcCoreNetworkAttachmentId = loJResp.StringOf("NetworkRoutes[i].Destinations[j].CoreNetworkAttachmentId")
lcEdgeLocation = loJResp.StringOf("NetworkRoutes[i].Destinations[j].EdgeLocation")
lcResourceId = loJResp.StringOf("NetworkRoutes[i].Destinations[j].ResourceId")
lcResourceType = loJResp.StringOf("NetworkRoutes[i].Destinations[j].ResourceType")
lcSegmentName = loJResp.StringOf("NetworkRoutes[i].Destinations[j].SegmentName")
lcTransitGatewayAttachmentId = loJResp.StringOf("NetworkRoutes[i].Destinations[j].TransitGatewayAttachmentId")
j = j + 1
ENDDO
i = i + 1
ENDDO
* A sample JSON response body parsed by the above code:
* {
* "CoreNetworkSegmentEdge": {
* "CoreNetworkId": "string",
* "EdgeLocation": "string",
* "SegmentName": "string"
* },
* "NetworkRoutes": [
* {
* "DestinationCidrBlock": "string",
* "Destinations": [
* {
* "CoreNetworkAttachmentId": "string",
* "EdgeLocation": "string",
* "ResourceId": "string",
* "ResourceType": "string",
* "SegmentName": "string",
* "TransitGatewayAttachmentId": "string"
* }
* ],
* "PrefixListId": "string",
* "State": "string",
* "Type": "string"
* }
* ],
* "RouteTableArn": "string",
* "RouteTableTimestamp": number,
* "RouteTableType": "string"
* }
RELEASE loRest
RELEASE loAuthAws
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody
RELEASE loJResp