{"__v":0,"_id":"588f722bbcace50f0052b9eb","category":{"version":"588f722bbcace50f0052b9e1","project":"565f5fa26bafd40d0030a064","_id":"588f722bbcace50f0052b9e2","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-03T19:46:10.966Z","from_sync":false,"order":0,"slug":"introduction","title":"Getting Started"},"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":["57ea87ef1780cd170064f279"],"next":{"pages":[],"description":""},"createdAt":"2015-12-08T19:38:37.398Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"At the core of nanoscale.io is the Workflow that determines how an API’s Proxy Endpoint responds to an incoming request. Developers have access to a powerful request-response lifecycle with hooks for custom business logic at various steps, and the ability to invoke one or more Remote Endpoints in sequence or parallel.\n \nAll business logic is written in familiar JavaScript syntax, with access to standard JavaScript functions and the popular Underscore.js library for additional helper functions. Within the scope of a Proxy Endpoint’s Workflow, developers have full access to the Request Object (headers, params, body and others) and Response Object (headers, body, status). For a full list of available JavaScript functions and objects, see the [JavaScript Object Reference](doc:javascript-object-reference).\n \nA Proxy Endpoint’s Workflow can consist of one or more Components. There are three types of Components available:\n\n## 1. Single Call Component\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/RSOXrEJSe7CblQX8HXBQ_topics-workflow-overview-single-call-component-diagram.png\",\n        \"topics-workflow-overview-single-call-component-diagram.png\",\n        \"460\",\n        \"189\",\n        \"#678614\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nA Single Call component consists of: \n\n1. **Conditional Logic** - determines whether to skip to the end\n2. **Before Request Logic** - runs immediately before a remote endpoint is invoked\n3. **Invocation of a Remote Endpoint**\n4. **After Request Logic** - can be used to formulate the response\n\n## 2. Multi-Call Component\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/sUTuxgS4en03LwkSdhNA_topics-workflow-overview-multi-call-component-diagram.png\",\n        \"topics-workflow-overview-multi-call-component-diagram.png\",\n        \"460\",\n        \"189\",\n        \"#73944a\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nA Multi-Call component consists of: \n\n1. **Conditional Logic** - determines whether to skip to the end\n2. **Before Request Logic** - runs immediately before the remote endpoints are invoked\n3. **Invocation of Multiple Remote Endpoints in Parallel**\n4. **After Request Logic** - can be used to formulate a composite response\n\n## 3. Logic Component\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/wdQFoc6hSkKmhLSD3Jdm_topics-workflow-overview-logic-component-diagram.png\",\n        \"topics-workflow-overview-logic-component-diagram.png\",\n        \"460\",\n        \"58\",\n        \"#74944b\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nA Logic component consists of: \n\n1. **Conditional Logic** - determines whether to skip to the end\n2. **Main Logic** - where a response can be formulated.\n \n## Multiple Component Workflow\n\nA Workflow can consist of one or more of these Components in any sequential order. For example, a Workflow can be comprised of one of each of the Component types, which would look like the illustration below:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/hMduMBnWShueNdwvAW74_topics-workflow-overview-multiple-component-workflow-diagram.png\",\n        \"topics-workflow-overview-multiple-component-workflow-diagram.png\",\n        \"467\",\n        \"472\",\n        \"#74944a\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nFor more details on Proxy Endpoints, please visit the [Proxy Endpoints](doc:proxy-endpoints) section. For a full list of available JavaScript functions and objects, see the [JavaScript Object Reference](doc:javascript-object-reference) section.","excerpt":"","slug":"request-response-lifecycle","type":"basic","title":"Request/Response Lifecycle"}

Request/Response Lifecycle


At the core of nanoscale.io is the Workflow that determines how an API’s Proxy Endpoint responds to an incoming request. Developers have access to a powerful request-response lifecycle with hooks for custom business logic at various steps, and the ability to invoke one or more Remote Endpoints in sequence or parallel. All business logic is written in familiar JavaScript syntax, with access to standard JavaScript functions and the popular Underscore.js library for additional helper functions. Within the scope of a Proxy Endpoint’s Workflow, developers have full access to the Request Object (headers, params, body and others) and Response Object (headers, body, status). For a full list of available JavaScript functions and objects, see the [JavaScript Object Reference](doc:javascript-object-reference). A Proxy Endpoint’s Workflow can consist of one or more Components. There are three types of Components available: ## 1. Single Call Component [block:image] { "images": [ { "image": [ "https://files.readme.io/RSOXrEJSe7CblQX8HXBQ_topics-workflow-overview-single-call-component-diagram.png", "topics-workflow-overview-single-call-component-diagram.png", "460", "189", "#678614", "" ] } ] } [/block] A Single Call component consists of: 1. **Conditional Logic** - determines whether to skip to the end 2. **Before Request Logic** - runs immediately before a remote endpoint is invoked 3. **Invocation of a Remote Endpoint** 4. **After Request Logic** - can be used to formulate the response ## 2. Multi-Call Component [block:image] { "images": [ { "image": [ "https://files.readme.io/sUTuxgS4en03LwkSdhNA_topics-workflow-overview-multi-call-component-diagram.png", "topics-workflow-overview-multi-call-component-diagram.png", "460", "189", "#73944a", "" ] } ] } [/block] A Multi-Call component consists of: 1. **Conditional Logic** - determines whether to skip to the end 2. **Before Request Logic** - runs immediately before the remote endpoints are invoked 3. **Invocation of Multiple Remote Endpoints in Parallel** 4. **After Request Logic** - can be used to formulate a composite response ## 3. Logic Component [block:image] { "images": [ { "image": [ "https://files.readme.io/wdQFoc6hSkKmhLSD3Jdm_topics-workflow-overview-logic-component-diagram.png", "topics-workflow-overview-logic-component-diagram.png", "460", "58", "#74944b", "" ] } ] } [/block] A Logic component consists of: 1. **Conditional Logic** - determines whether to skip to the end 2. **Main Logic** - where a response can be formulated. ## Multiple Component Workflow A Workflow can consist of one or more of these Components in any sequential order. For example, a Workflow can be comprised of one of each of the Component types, which would look like the illustration below: [block:image] { "images": [ { "image": [ "https://files.readme.io/hMduMBnWShueNdwvAW74_topics-workflow-overview-multiple-component-workflow-diagram.png", "topics-workflow-overview-multiple-component-workflow-diagram.png", "467", "472", "#74944a", "" ] } ] } [/block] For more details on Proxy Endpoints, please visit the [Proxy Endpoints](doc:proxy-endpoints) section. For a full list of available JavaScript functions and objects, see the [JavaScript Object Reference](doc:javascript-object-reference) section.