doc-exports/docs/fg/api-ref/functiongraph_06_0203.html
Chen, Junjie 7914103af1 FG API 20230725 version
Reviewed-by: Eotvos, Oliver <oliver.eotvos@t-systems.com>
Co-authored-by: Chen, Junjie <chenjunjie@huawei.com>
Co-committed-by: Chen, Junjie <chenjunjie@huawei.com>
2024-04-09 08:59:29 +00:00

122 lines
8.7 KiB
HTML

<a name="functiongraph_06_0203"></a><a name="functiongraph_06_0203"></a>
<h1 class="topictitle1">Example 2: Using an APIG Trigger to Obtain a Static Web Page</h1>
<div id="body0000001483295945"><div class="section" id="functiongraph_06_0203__section11773144817815"><h4 class="sectiontitle">Scenario</h4><p id="functiongraph_06_0203__p49911552162316">This example guides you through the procedure for creating a Python 2.7 function and associating an APIG trigger with it to obtain a static web page.</p>
<p id="functiongraph_06_0203__p414824518258">For details about how to call APIs, see <a href="functiongraph_06_0200.html">Calling APIs</a>.</p>
</div>
<div class="section" id="functiongraph_06_0203__section1835181812285"><h4 class="sectiontitle">Prerequisites</h4><p id="functiongraph_06_0203__p1617616635011">You have created an API group in APIG, and have recorded the ID and subdomain name of the API group.</p>
</div>
<div class="section" id="functiongraph_06_0203__section780392783814"><h4 class="sectiontitle">General Procedure</h4><p id="functiongraph_06_0203__p1455819135717">Create a FunctionGraph function and associate an APIG trigger with it to obtain a static web page. The procedure is as follows:</p>
<ol id="functiongraph_06_0203__ol1214112417578"><li id="functiongraph_06_0203__li99482315813"><a href="functiongraph_06_0108.html">Creating a Function</a>: Create a function to return a static web page.</li><li id="functiongraph_06_0203__li103781725175120"><a href="functiongraph_06_0122.html">Creating a Trigger</a>: Create an APIG trigger.</li><li id="functiongraph_06_0203__li19690152721210">Call the API of the APIG trigger to obtain a static page.</li></ol>
</div>
<div class="section" id="functiongraph_06_0203__section5121646125111"><a name="functiongraph_06_0203__section5121646125111"></a><a name="section5121646125111"></a><h4 class="sectiontitle">Step 1: Create a Function to Return a Static Web Page</h4><p id="functiongraph_06_0203__p14668451125116">URI: <strong id="functiongraph_06_0203__b1014114229556">POST /v2/</strong><em id="functiongraph_06_0203__i3142102225517">{project_id}</em><strong id="functiongraph_06_0203__b414212212553">/fgs/functions</strong></p>
<p id="functiongraph_06_0203__p19789173461318">For details, see <a href="functiongraph_06_0108.html">Creating a Function</a>.</p>
<ul id="functiongraph_06_0203__ul104224515521"><li id="functiongraph_06_0203__li5840141415149">Sample request<pre class="screen" id="functiongraph_06_0203__screen795591013534">POST https://{Endpoint}/v2/{project_id}/fgs/functions
{
"code_filename": "index.zip",
"code_type": "inline",
"func_code": {
"file": "UEsDBAoAAAAIABY7vFD7lxPkAgMAALoHAAAIAAAAaW5kZXgucHndVdtu00AQfc9XrMKDExQ7zqW50VYqFZRKIFUQhFBVobU9iU1tr9mdbRKqSHwNH8aXMLtxrgoS8ISIosg7c+bszNnjzRPmPnVZKKIkn440TtyBCVQcx6mMY2ATkaZiRjmWKMZzdnFzfcXgAXJkYsI4UzwrUoLpPMRE5B77KDQLCYigkGFMVescCxZMQQq0IDokcl4kruVyEYiGI5TU66VXqTxWGKvGiMUbwFhE1RGrXr0YVxsmXHCMTaBpNmvGQK1uEzdc8gwQpCKIYTFxKeYLU7HCUnBp8V80yMU7lNTYsbKcIqaKfjclMfBoDzR3FfKpxZl2bCMUfiXomWIz7GU5tNXw3oM5hBrBpfE9rdwZod22xzP+VeR8prxQZOvq9wqkezElTQxHqrkrCb1wjSBN32v5rPZa8zrLp/NPlG22fN8fbJsMRGTH/fHtO31X2kigaRVeihxhjtv+j3Zfgq+t7lHU7XT6nV479NthP+r328Mh9Af9QSuAoBu01kU016qg2wq6J8A7bt8PTtxWC3pu0A8itzcMTjiHgEiGZbNL67gkK4QkZ6n102cl8vVzwBX0upVKBBMW8zxKQdasXRpkXztMfWQbKOgckTl02CEoxcoZ2ESKzFiOvCeT6RSkU7FwlItVnfmQvIXIFYwXBbCzlR1vnaP+cO5unV24c2dZYB5Cgb9kdKh9rlMsN08mBwBCxJilzpbALN+WGCJ43CTMx6FjQ60uRQTOiLV9v7GfTtRzK9uLnF5xiAgzlhoOQKWXndEBuT1NaxTzilJ7K3vM6V2jnp6xMOZSAZ7Za6O6V7o82MI4kfhXZ+gFvS7YhmrOqaE6P41b5x8gJecDQ8E0TfqyvDauJC/i0yYBTu225059y73ckRm1zK1hvEhnhart6lZfqQ3pMb1NzY7eZvkP6c2LIk1CbqRomtb+UufH6j3Yu+CBpxqqy99VcVeNjYoKtnKVfv7fHXqTAmXMTaNQ6hDtH5iWKZslGDN7QbBiczfsmezMEDT2Q0bWP/TzgdD1n1BLAQIeAwoAAAAIABY7vFD7lxPkAgMAALoHAAAIAAAAAAAAAAAAAADzAgAAAABpbmRleC5weVBLBQYAAAAAAQABADYAAAAoAwAAAAA="
},
"func_name": "get_html",
"handler": "index.handler",
"memory_size": 256,
"package": "default",
"runtime": "Python2.7",
"timeout": 5
}</pre>
</li><li id="functiongraph_06_0203__li687731534">Sample response<pre class="screen" id="functiongraph_06_0203__screen1560121485319">{
"func_urn": "urn:fss:{project_name}:{project_id}:function:default:get_html:latest",
"func_name": "get_html",
"domain_id": "89fexxxd636",
"namespace": "{project_id}",
"project_name": "xxx",
"package": "default",
"runtime": "Python2.7",
"timeout": 5,
"handler": "index.handler",
"memory_size": 256,
"cpu": 400,
"code_type": "inline",
"code_filename": "index.zip",
"code_size": 884,
"digest": "b08fef5e97dd130037978db07f0e9109aa43a191517cd1196bcab822f17dddcf37f7506a15691177962f9803ba6d170a1c87aafb4fa1b9f0d07f9415642b26d2",
"version": "latest",
"image_name": "latest-200604105808@we0qo",
"last_modified": "2020-06-04T10:58:08+08:00",
"strategy_config": {
"concurrency": -1
},
"StrategyConfig": {},
"enterprise_project_id": "0"
}</pre>
<p id="functiongraph_06_0203__p11601217418">Record the URN of the function, that is, the value of <strong id="functiongraph_06_0203__b2079454746518">func_urn</strong> in the response.</p>
</li></ul>
</div>
<div class="section" id="functiongraph_06_0203__section117522481318"><h4 class="sectiontitle">Step 2: Create an APIG Trigger</h4><p id="functiongraph_06_0203__p1261412284014">URI: <strong id="functiongraph_06_0203__b168666352265331">POST /v2/</strong><em id="functiongraph_06_0203__i172435966565331">{project_id}</em><strong id="functiongraph_06_0203__b144637313065331">/fgs/triggers/</strong><em id="functiongraph_06_0203__i109133180665331">{function_urn}</em></p>
<p id="functiongraph_06_0203__p17634513409">For details, see <a href="functiongraph_06_0122.html">Creating a Trigger</a>.</p>
<ul id="functiongraph_06_0203__ul5165132910218"><li id="functiongraph_06_0203__li3251330101011">Sample request<pre class="screen" id="functiongraph_06_0203__screen449195717210">POST https://{Endpoint}/v2/{project_id}/fgs/triggers/{function_urn}
{
"event_data": {
"group_id": "a9ad0d5df4d7475c9bc35a7c17d89304",
"env_id": "DEFAULT_ENVIRONMENT_RELEASE_ID",
"auth": "NONE",
"protocol": "HTTP",
"name": "API_GetHtml",
"path": "/test",
"match_mode": "SWA",
"req_method": "ANY",
"backend_type": "FUNCTION",
"sl_domain": "a9ad0d5df4d7475c9bc35a7c17d89304.apig.xxx.xxxapis.com",
"type": 1,
"env_name": "RELEASE"
},
"event_type_code": "APICreated",
"trigger_status": "ACTIVE",
"trigger_type_code": "APIG"
}</pre>
<p id="functiongraph_06_0203__p161902013177"><strong id="functiongraph_06_0203__b1167013314568">function_urn</strong> indicates the function URN recorded in <a href="#functiongraph_06_0203__section5121646125111">Step 1: Create a Function to Return a Static Web Page</a>, <strong id="functiongraph_06_0203__b16161101795610">group_id</strong> indicates an API group ID, and <strong id="functiongraph_06_0203__b722719272567">sl_domain</strong> indicates the subdomain name that APIG allocates to the API group.</p>
</li><li id="functiongraph_06_0203__li10664548328">Sample response<pre class="screen" id="functiongraph_06_0203__screen19442704318">{
"trigger_id": "1b3ec74b86454aa39001a9f89cc70ee2",
"trigger_type_code": "APIG",
"trigger_status": "ACTIVE",
"event_data": {
"api_id": "cbc698153d1f4265bdd8384b5cf6e581",
"api_name": "API_GetHtml",
"auth": "NONE",
"env_id": "",
"env_name": "",
"func_info": {
"function_urn": "urn:fss:{project_name}:{project_id}:function:default:get_html",
"invocation_type": "sync",
"timeout": 5000,
"version": "latest"
},
"group_id": "a9ad0d5df4d7475c9bc35a7c17d89304",
"group_name": "APIGroup_gethtml",
"invoke_url": "http://a9ad0d5df4d7475c9bc35a7c17d89304.apig.xxx.xxxapis.com/test",
"match_mode": "SWA",
"name": "API_GetHtml",
"path": "/test",
"protocol": "HTTP",
"req_method": "ANY",
"triggerid": "1b3ec74b86454aa39001a9f89cc70ee2",
"type": 1
},
"last_updated_time": "2020-06-04T17:14:32+08:00",
"created_time": "2020-06-04T17:14:32+08:00"
}</pre>
<p id="functiongraph_06_0203__p1615016496223">Record the value of <strong id="functiongraph_06_0203__b93321056135617">invoke_url</strong>.</p>
</li></ul>
</div>
<div class="section" id="functiongraph_06_0203__section1540622851115"><h4 class="sectiontitle">Step 3: Call the API of the APIG Trigger to Obtain a Static Web Page</h4><p id="functiongraph_06_0203__p0587144919110">Enter the value of <strong id="functiongraph_06_0203__b1318122135715">invoke_url</strong> in the address bar of a browser to obtain a static web page.</p>
<div class="fignone" id="functiongraph_06_0203__fig19568175732310"><span class="figcap"><b>Figure 1 </b>Calling the API</span><br><span><img id="functiongraph_06_0203__image3569175752318" src="en-us_image_0000001483376169.png"></span></div>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="functiongraph_06_0201.html">Examples</a></div>
</div>
</div>