{"id":10262,"date":"2021-07-12T11:00:25","date_gmt":"2021-07-12T02:00:25","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=10262"},"modified":"2021-07-12T11:16:32","modified_gmt":"2021-07-12T02:16:32","slug":"a-touch-to-serverless-framework-final-part","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/10262","title":{"rendered":"A touch to serverless framework &#8211; final part"},"content":{"rendered":"\n<p>We have created our serverless endpoint last week and lets tweak a bit more today by adding some parameters to our endpoint. Lets get started.<\/p>\n\n\n\n<p>We don&#8217;t have to modify serverless.yml and lets keep the same way we did before.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>events:\n      - http:\n          path: sample-endpoint\n          method: GET<\/code><\/pre>\n\n\n\n<p>Lets modify the <code>handler.js<\/code> as we are adding a <code>name<\/code> parameter to our endpoint and get a different response depending on the input parameter. We will add a conditional statement for our <code>name<\/code> parameter in our handler.js like this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (event.queryStringParameters &amp;&amp; event.queryStringParameters.name) {\n    return {\n      statusCode: 200,\n      body: JSON.stringify(\n        {\n          message: 'Hello' + event.queryStringParameters.name,\n          input: event,\n        },\n        null,\n        2\n      ),\n    };\n  }<\/code><\/pre>\n\n\n\n<p>So this will be our final result of <code>handler.js<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>'use strict';\n\nmodule.exports.hello = async (event) =&gt; {\n\n\n  if (event.queryStringParameters &amp;&amp; event.queryStringParameters.name) {\n    return {\n      statusCode: 200,\n      body: JSON.stringify(\n        {\n          message: 'Hello' + event.queryStringParameters.name,\n          input: event,\n        },\n        null,\n        2\n      ),\n    };\n  }\n\n  return {\n    statusCode: 200,\n    body: JSON.stringify(\n      {\n        message: 'Go Serverless v1.0! Your function executed successfully!',\n        input: event,\n      },\n      null,\n      2\n    ),\n  }\n};\n<\/code><\/pre>\n\n\n\n<p>Lets deploy our code and see the result.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"386\" src=\"\/appnews\/wp-content\/uploads\/sites\/4\/2021\/07\/17.sls_queryparam_deploy-1024x386.png\" alt=\"\" class=\"wp-image-10263\" srcset=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/07\/17.sls_queryparam_deploy-1024x386.png 1024w, https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/07\/17.sls_queryparam_deploy.png 1928w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Lets go to the endpoint from the browser but this time we will add a <code>name<\/code> parameter at the end of the url like this<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>?name=Hlaing<\/code><\/pre>\n\n\n\n<p>As a final result, we will get a response like this.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"702\" src=\"\/appnews\/wp-content\/uploads\/sites\/4\/2021\/07\/18.sls_param_result-1024x702.png\" alt=\"\" class=\"wp-image-10264\" srcset=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/07\/18.sls_param_result-1024x702.png 1024w, https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/07\/18.sls_param_result.png 2024w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>You can see the result of our name parameter in the json response of message data.<\/p>\n\n\n\n<p>That&#8217;s all for today and we have successfully added a new parameter to our endpoint.<\/p>\n\n\n\n<p>As a conclusion note, I have to say we can still do many things through this serverless project. We can also create other method type endpoint like POST. We can also create services like S3 buckets, DBs and so on through serverless.yml and deploying it. But let me stop the article series here as I also intended to get you a starting point to the serverless framework and I think you got it.<\/p>\n\n\n\n<p>See you again . Yuuma<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/10262\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/10262\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"A touch to serverless framework &#8211; final part\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/10262\" data-text=\"A touch to serverless framework &#8211; final part\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/10262\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/10262\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>We have created our serverless endpoint last week and lets tweak a bit more today by adding some parameters to [&hellip;]<\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[35],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/10262"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=10262"}],"version-history":[{"count":3,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/10262\/revisions"}],"predecessor-version":[{"id":10268,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/10262\/revisions\/10268"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=10262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=10262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=10262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}