{"__v":0,"_id":"588f722cbcace50f0052ba13","category":{"version":"588f722bbcace50f0052b9e1","project":"565f5fa26bafd40d0030a064","_id":"588f722bbcace50f0052b9e4","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-26T05:04:48.794Z","from_sync":false,"order":2,"slug":"samples-and-tutorials","title":"How Tos & Examples"},"parentDoc":null,"project":"565f5fa26bafd40d0030a064","user":"565f3941ea46251700972783","version":{"__v":1,"_id":"588f722bbcace50f0052b9e1","project":"565f5fa26bafd40d0030a064","createdAt":"2017-01-30T17:04:43.410Z","releaseDate":"2017-01-30T17:04:43.410Z","categories":["588f722bbcace50f0052b9e2","588f722bbcace50f0052b9e3","588f722bbcace50f0052b9e4","588f722bbcace50f0052b9e5","588f722bbcace50f0052b9e6","588f722bbcace50f0052b9e7"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"5.3.0","version":"5.3.0"},"updates":["56d84b9cb20d260b00265721","57e54d23f3d7fc0e009c50ec","57ea8b871780cd170064f280"],"next":{"pages":[],"description":""},"createdAt":"2015-12-31T23:42:15.199Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":5,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Important\",\n  \"body\": \"In order to run these examples, please make sure you've followed the [Quick Start Guide](doc:quick-start-guide). You'll need to have signed up with <a target=\\\"_blank\\\" href=\\\"https://dashboard.nanoscale.io/#/registration\\\">nanoscale.io</a> and downloaded the <a target=\\\"_blank\\\" href=\\\"http://downloads.justapis.com/v5.0.0/samples.json\\\">Sample APIs</a> we provide.\\n\\nThe instructions in this tutorial refer to the sample Proxy Endpoint called “CRUD - Show an event” in the sample API that you imported in the Quick Start Guide steps, and assumes you have a nanoscale.io account. If you have not imported the sample API or signed up for <a target=\\\"_blank\\\" href=\\\"https://dashboard.nanoscale.io/#/registration\\\">nanoscale.io</a>, please do so now.\"\n}\n[/block]\nThis tutorial shows how to create a Proxy Endpoint that invokes a Remote Endpoint to show an event record.\n \n## Step 1\n\nThis Proxy Endpoint requires you to first define a Remote Endpoint: “Event – GET”. Within the sample APIs Remote Endpoint list, find “Event - GET”, which is meant to simulate a service to create event information by an id, and click the row.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/6RdXAv1uQiSLwAEQQbe8_samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step1.png\",\n        \"samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step1.png\",\n        \"3324\",\n        \"1344\",\n        \"#5389c6\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n## Step 2\n\nWhen you are in edit mode, you will see that this Remote Endpoint has a few properties that were specified when it was created.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/nFnP8h2QSY6Zh3k9xJgt_samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step2.png\",\n        \"samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step2.png\",\n        \"3320\",\n        \"1814\",\n        \"#50606a\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n1. The Remote Endpoint’s **name** is: “Event - GET”, which is used for display purposes in the Admin Web App.\n\n2. The Remote Endpoint’s **codename** is: “event”, which determines how the Remote Endpoint Request and Response Objects are referred to within JavaScript logic blocks.\n\n3. The Remote Endpoint **URL** has been left blank. This is the URL of the external API endpoint that you are calling which will be set in Proxy Endpoint logic.\n\n4. The **Method** of external API endpoint to validate token is GET.\n\n5. A **header** has been defined to pass basic auth credentials required by the Remote Endpoint.\n\n6. There are no **query parameters** and **environment data** required to be set for this Remote Endpoint.\n\n## Step 3\n\nNow you are ready to define the Proxy Endpoint that the above defined Remote Endpoint to show the data. Find the “CRUD - Show an event”, which should appear in the list of Proxy Endpoints, and click the row.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/Sf3dVUISsujTUsk80Kvu_samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step3.png\",\n        \"samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step3.png\",\n        \"3326\",\n        \"1520\",\n        \"#6f9b58\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n## Step 4\n\nWhen you are in edit mode, you will see that this Proxy Endpoint has several properties that were specified when it was created.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/7OuxaKfyREmmz4CpLgjp_samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step4.png\",\n        \"samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step4.png\",\n        \"3328\",\n        \"1532\",\n        \"#50616c\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n1. The Proxy Endpoint’s **name** is: “CRUD - Show an event”, which is used for display purposes in the Admin Web App.\n\n2. The **Active** status is set to on, which means that this Proxy Endpoint will run if the server receives a request for it.\n\n3. This Proxy Endpoint is assigned to the “Dev” **Environment**, and any environment variables used in will be populated from the “Dev” environment.\n\n4. This Proxy Endpoint is assigned to the “Event calls” **Group**.\n\n5. There is one **Route** defined, which is a GET method as “/events/{id}”. This means that if the Host is organic-apparel-7319.justapis.io, the full URL for this Proxy Endpoint is <a target=\"_blank\" href=\"https://organic-apparel-7319.justapis.io/events/{id}\">https://organic-apparel-7319.justapis.io/events/{id}</a>. Id will be passed as part of the URL.\n\nNote that there is one steps in this Proxy Endpoint Workflow, which is Single Call Component, as denoted by the following icon.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/NC64VvERzas3G00lLYaQ_samples-and-tutorials-multiple-remote-endpoints-in-sequence-single-call-component-icon.png\",\n        \"samples-and-tutorials-multiple-remote-endpoints-in-sequence-single-call-component-icon.png\",\n        \"1280\",\n        \"91\",\n        \"#4c647c\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n## Step 5\n\nClick on the Single Call Component icon to view the details of this step in the workflow.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/GjsrTyjTFOZ950m0wqyF_samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step5.png\",\n        \"samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step5.png\",\n        \"3334\",\n        \"1542\",\n        \"#339bd5\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nYou will see that this Single Call is comprised of several sub-steps:\n \n1. **Conditional** set to “If”, which means that any JavaScript logic specified in the Conditional logic block must evaluate to “true” to continue. Otherwise, the workflow will skip to the end.\n\n2. The Conditional Logic block has is empty.\n\n3. The Before Request logic block has the following JavaScript code.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"event.request = new AP.HTTP.Request();\\nevent.request.url = env.mockEventsUrl + \\\"read/\\\" + request.params.id;\\nevent.request.method = \\\"GET\\\";\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nThis code creates a new AP.HTTP.Request object based on the Remote Endpoint response that we codenamed “event” in step 2-2 above. It then sets this request object’s URL based on an environment variable called mockEventsUrl, appends the request parameter, and sets the method to GET.\n\n4. This Single Call component calls the Remote Endpoint “Event - GET” defined in step 2-1 above.\n\n5. The Endpoint name override has been left blank.\n\n6. The After request logic block has the following JavaScript code.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"response_data = JSON.parse(response.body).response.results;\\n \\nresponse_data.first_attendee = response_data.attendees[0];\\n \\nif(response_data.sessions.key1){\\n  response_data.first_session = response_data.sessions.key1;\\n}\\n \\nresponse_data.end_date = response_data.endDate;\\ndelete response_data.endDate;\\n \\nresponse.body = JSON.stringify(response_data);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nThis code manipulates the Response data, renaming the “endDate\" property to “ nd_date”, and creating a key for the first attendee and first session.\n\n## Step 6\n\nNow let us test this Proxy Endpoint. Open a new browser window or tab, and invoke the Proxy Endpoint using the following URLs (if you have changed the default Host, please use your new hostname instead).\n\n<a target=\"_blank\" href=\"https://organic-apparel-7319.justapis.io/events/101\">https://organic-apparel-7319.justapis.io/events/101</a>\n\nYou should see the resulting message in your browser window.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/kVPN42d7RoCEyrDjAm87_proxy.png\",\n        \"proxy.png\",\n        \"568\",\n        \"488\",\n        \"#735145\",\n        \"\"\n      ],\n      \"sizing\": \"original\",\n      \"border\": false\n    }\n  ]\n}\n[/block]\nCongratulations, you have completed this tutorial.","excerpt":"","slug":"proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record","type":"basic","title":"Proxy Endpoint That Invokes a Remote Endpoint To Retrieve a Record"}

Proxy Endpoint That Invokes a Remote Endpoint To Retrieve a Record


[block:callout] { "type": "info", "title": "Important", "body": "In order to run these examples, please make sure you've followed the [Quick Start Guide](doc:quick-start-guide). You'll need to have signed up with <a target=\"_blank\" href=\"https://dashboard.nanoscale.io/#/registration\">nanoscale.io</a> and downloaded the <a target=\"_blank\" href=\"http://downloads.justapis.com/v5.0.0/samples.json\">Sample APIs</a> we provide.\n\nThe instructions in this tutorial refer to the sample Proxy Endpoint called “CRUD - Show an event” in the sample API that you imported in the Quick Start Guide steps, and assumes you have a nanoscale.io account. If you have not imported the sample API or signed up for <a target=\"_blank\" href=\"https://dashboard.nanoscale.io/#/registration\">nanoscale.io</a>, please do so now." } [/block] This tutorial shows how to create a Proxy Endpoint that invokes a Remote Endpoint to show an event record. ## Step 1 This Proxy Endpoint requires you to first define a Remote Endpoint: “Event – GET”. Within the sample APIs Remote Endpoint list, find “Event - GET”, which is meant to simulate a service to create event information by an id, and click the row. [block:image] { "images": [ { "image": [ "https://files.readme.io/6RdXAv1uQiSLwAEQQbe8_samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step1.png", "samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step1.png", "3324", "1344", "#5389c6", "" ] } ] } [/block] ## Step 2 When you are in edit mode, you will see that this Remote Endpoint has a few properties that were specified when it was created. [block:image] { "images": [ { "image": [ "https://files.readme.io/nFnP8h2QSY6Zh3k9xJgt_samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step2.png", "samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step2.png", "3320", "1814", "#50606a", "" ] } ] } [/block] 1. The Remote Endpoint’s **name** is: “Event - GET”, which is used for display purposes in the Admin Web App. 2. The Remote Endpoint’s **codename** is: “event”, which determines how the Remote Endpoint Request and Response Objects are referred to within JavaScript logic blocks. 3. The Remote Endpoint **URL** has been left blank. This is the URL of the external API endpoint that you are calling which will be set in Proxy Endpoint logic. 4. The **Method** of external API endpoint to validate token is GET. 5. A **header** has been defined to pass basic auth credentials required by the Remote Endpoint. 6. There are no **query parameters** and **environment data** required to be set for this Remote Endpoint. ## Step 3 Now you are ready to define the Proxy Endpoint that the above defined Remote Endpoint to show the data. Find the “CRUD - Show an event”, which should appear in the list of Proxy Endpoints, and click the row. [block:image] { "images": [ { "image": [ "https://files.readme.io/Sf3dVUISsujTUsk80Kvu_samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step3.png", "samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step3.png", "3326", "1520", "#6f9b58", "" ] } ] } [/block] ## Step 4 When you are in edit mode, you will see that this Proxy Endpoint has several properties that were specified when it was created. [block:image] { "images": [ { "image": [ "https://files.readme.io/7OuxaKfyREmmz4CpLgjp_samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step4.png", "samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step4.png", "3328", "1532", "#50616c", "" ] } ] } [/block] 1. The Proxy Endpoint’s **name** is: “CRUD - Show an event”, which is used for display purposes in the Admin Web App. 2. The **Active** status is set to on, which means that this Proxy Endpoint will run if the server receives a request for it. 3. This Proxy Endpoint is assigned to the “Dev” **Environment**, and any environment variables used in will be populated from the “Dev” environment. 4. This Proxy Endpoint is assigned to the “Event calls” **Group**. 5. There is one **Route** defined, which is a GET method as “/events/{id}”. This means that if the Host is organic-apparel-7319.justapis.io, the full URL for this Proxy Endpoint is <a target="_blank" href="https://organic-apparel-7319.justapis.io/events/{id}">https://organic-apparel-7319.justapis.io/events/{id}</a>. Id will be passed as part of the URL. Note that there is one steps in this Proxy Endpoint Workflow, which is Single Call Component, as denoted by the following icon. [block:image] { "images": [ { "image": [ "https://files.readme.io/NC64VvERzas3G00lLYaQ_samples-and-tutorials-multiple-remote-endpoints-in-sequence-single-call-component-icon.png", "samples-and-tutorials-multiple-remote-endpoints-in-sequence-single-call-component-icon.png", "1280", "91", "#4c647c", "" ] } ] } [/block] ## Step 5 Click on the Single Call Component icon to view the details of this step in the workflow. [block:image] { "images": [ { "image": [ "https://files.readme.io/GjsrTyjTFOZ950m0wqyF_samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step5.png", "samples-and-tutorials-create-a-proxy-endpoint-that-invokes-a-remote-endpoint-to-retrieve-a-record-step5.png", "3334", "1542", "#339bd5", "" ] } ] } [/block] You will see that this Single Call is comprised of several sub-steps: 1. **Conditional** set to “If”, which means that any JavaScript logic specified in the Conditional logic block must evaluate to “true” to continue. Otherwise, the workflow will skip to the end. 2. The Conditional Logic block has is empty. 3. The Before Request logic block has the following JavaScript code. [block:code] { "codes": [ { "code": "event.request = new AP.HTTP.Request();\nevent.request.url = env.mockEventsUrl + \"read/\" + request.params.id;\nevent.request.method = \"GET\";", "language": "javascript" } ] } [/block] This code creates a new AP.HTTP.Request object based on the Remote Endpoint response that we codenamed “event” in step 2-2 above. It then sets this request object’s URL based on an environment variable called mockEventsUrl, appends the request parameter, and sets the method to GET. 4. This Single Call component calls the Remote Endpoint “Event - GET” defined in step 2-1 above. 5. The Endpoint name override has been left blank. 6. The After request logic block has the following JavaScript code. [block:code] { "codes": [ { "code": "response_data = JSON.parse(response.body).response.results;\n \nresponse_data.first_attendee = response_data.attendees[0];\n \nif(response_data.sessions.key1){\n response_data.first_session = response_data.sessions.key1;\n}\n \nresponse_data.end_date = response_data.endDate;\ndelete response_data.endDate;\n \nresponse.body = JSON.stringify(response_data);", "language": "javascript" } ] } [/block] This code manipulates the Response data, renaming the “endDate" property to “ nd_date”, and creating a key for the first attendee and first session. ## Step 6 Now let us test this Proxy Endpoint. Open a new browser window or tab, and invoke the Proxy Endpoint using the following URLs (if you have changed the default Host, please use your new hostname instead). <a target="_blank" href="https://organic-apparel-7319.justapis.io/events/101">https://organic-apparel-7319.justapis.io/events/101</a> You should see the resulting message in your browser window. [block:image] { "images": [ { "image": [ "https://files.readme.io/kVPN42d7RoCEyrDjAm87_proxy.png", "proxy.png", "568", "488", "#735145", "" ], "sizing": "original", "border": false } ] } [/block] Congratulations, you have completed this tutorial.