﻿
{"id":17256,"date":"2020-08-08T00:26:58","date_gmt":"2020-08-08T00:26:58","guid":{"rendered":"https:\/\/www.gencayyildiz.com\/blog\/?p=17256"},"modified":"2020-08-08T00:26:58","modified_gmt":"2020-08-08T00:26:58","slug":"azure-functions-serisi-9-http-trigger","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/azure-functions-serisi-9-http-trigger\/","title":{"rendered":"Azure Functions Serisi #9 &#8211; Http Trigger"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Bu i\u00e7eri\u011fimizde Azure Function trigger t\u00fcrlerinden ilki ve en \u00e7ok kullan\u0131lan\u0131 olan Http Trigger \u00fczerine detayl\u0131ca konu\u015fuyor olaca\u011f\u0131z.<\/p>\n<h3 style=\"color: #e83e8c;\">Http Trigger Nedir?<\/h3>\n<p>Http Trigger, taraf\u0131m\u0131za verdi\u011fi endpointler arac\u0131l\u0131\u011f\u0131yla tetiklenebilir bir fonksiyon \u00e7e\u015fididir.<\/p>\n<div id=\"attachment_17244\" style=\"width: 490px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-8-Azure-Function-Dosya-Yap\u0131s\u0131-2.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-17244\" class=\"size-full wp-image-17244\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-8-Azure-Function-Dosya-Yap\u0131s\u0131-2.jpg\" alt=\"Http Trigger Endpoint Listesi\" width=\"480\" height=\"102\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-8-Azure-Function-Dosya-Yap\u0131s\u0131-2.jpg 480w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-8-Azure-Function-Dosya-Yap\u0131s\u0131-2-300x64.jpg 300w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/a><p id=\"caption-attachment-17244\" class=\"wp-caption-text\">Bir \u00f6nceki\u00a0<a href=\"https:\/\/www.gencayyildiz.com\/blog\/azure-functions-serisi-8-azure-function-dosya-yapisi\/\" target=\"_blank\" rel=\"noopener noreferrer\">Azure Function Dosya Yap\u0131s\u0131<\/a> makalemizden \u00f6rnek Http Trigger endpoint g\u00f6rseli&#8230;<\/p><\/div>\n<h3 style=\"color: #e83e8c;\">Http Trigger Yap\u0131s\u0131 Nas\u0131ld\u0131r?<\/h3>\n<p>Http Trigger yap\u0131sal olarak; Route, Query String ve Request Body yap\u0131lanmas\u0131ndan meydana gelmektedir. Bu kavramlar\u0131n izahatlerini yapabilmek i\u00e7in a\u015fa\u011f\u0131daki function&#8217;\u0131 ele alal\u0131m;<br \/>\n<span style=\"font-size:10px;\">Not! Bu i\u00e7eri\u011fi anlamland\u0131rabilmek i\u00e7in bir Azure Function uygulamas\u0131n\u0131n nas\u0131l olu\u015fturuldu\u011funu bilmeniz gerekmektedir. Bunun i\u00e7in <a href=\"https:\/\/www.gencayyildiz.com\/blog\/azure-functions-yazi-serisi\/\" rel=\"noopener noreferrer\" target=\"_blank\">yaz\u0131 dizisi<\/a>ndeki \u00f6nceden kaleme al\u0131nm\u0131\u015f ilgili makalelerden istifade edebilirsiniz.<\/span><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public static class MyFunction\r\n    {\r\n        &#x5B;FunctionName(&quot;MyFunction&quot;)]\r\n        public static async Task&lt;IActionResult&gt; Run(\r\n            &#x5B;HttpTrigger(AuthorizationLevel.Function, &quot;get&quot;, &quot;post&quot;, Route = null)] HttpRequest req,\r\n            ILogger log)\r\n        {\r\n            string name = req.Query&#x5B;&quot;name&quot;];\r\n\r\n            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();\r\n            dynamic data = JsonConvert.DeserializeObject(requestBody);\r\n\r\n            return new OkObjectResult(data);\r\n        }\r\n    }\r\n<\/pre>\n<ul>\n<li><strong style=\"color: purple;\">Route<\/strong><br \/>\nYukar\u0131daki uygulamay\u0131 aya\u011fa kald\u0131rd\u0131\u011f\u0131m\u0131zda bizlere a\u015fa\u011f\u0131daki endpoint&#8217;i verecektir.<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger.jpg\" alt=\"Azure Functions Serisi #9 - Http Trigger\" width=\"564\" height=\"60\" class=\"aligncenter size-full wp-image-17268\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger.jpg 564w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-300x32.jpg 300w\" sizes=\"auto, (max-width: 564px) 100vw, 564px\" \/><\/a><br \/>\nBu endpoint&#8217;te ki &#8216;\/api\/<span style=\"color:red;\">MyFunction<\/span>&#8216; k\u0131rm\u0131z\u0131yla vurgulanan nokta 3. sat\u0131rdaki &#8216;[FunctionName(&#8220;MyFunction&#8221;)]&#8217; attribute&#8217;u sayesinde gelmektedir. &#8216;Run&#8217; fonksiyonunun &#8216;HttpRequest&#8217; t\u00fcr\u00fcnden olan &#8216;req&#8217; isimli parametresinin i\u015faretlendi\u011fi &#8216;HttpTrigger&#8217; attribute&#8217;unun &#8216;Route&#8217; parametresine odaklan\u0131rsan\u0131z e\u011fer, bu parametre bo\u015f oldu\u011fu s\u00fcrece varsay\u0131lan olarak endpoint ismini &#8216;FunctionName&#8217; attribute&#8217;undan alacakt\u0131r.<\/p>\n<p>&#8216;FunctionName&#8217; attribute&#8217;unun de\u011feri de\u011fi\u015ftirilirse endpoint a\u015fa\u011f\u0131da g\u00f6rece\u011finiz \u00fczere de\u011fi\u015fmi\u015f olacakt\u0131r.<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-1.jpg\" alt=\"Azure Functions Serisi #9 - Http Trigger\" width=\"725\" height=\"87\" class=\"aligncenter size-full wp-image-17271\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-1.jpg 725w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-1-300x36.jpg 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-1-720x87.jpg 720w\" sizes=\"auto, (max-width: 725px) 100vw, 725px\" \/><\/a><\/p>\n<p>Benzer mant\u0131kla &#8216;Route&#8217; parametresine girilen de\u011fer &#8216;FunctionName&#8217;i ezecek ve endpoint&#8217;i belirleyecektir.<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-2.jpg\" alt=\"Azure Functions Serisi #9 - Http Trigger\" width=\"715\" height=\"73\" class=\"aligncenter size-full wp-image-17273\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-2.jpg 715w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-2-300x31.jpg 300w\" sizes=\"auto, (max-width: 715px) 100vw, 715px\" \/><\/a><\/p>\n<p><em style=\"color:red;\">Route Parametre Tan\u0131mlama<\/em><br \/>\nKlasik Asp.NET Core uygulamalar\u0131ndaki gibi s\u00fcsl\u00fc parantezler e\u015fli\u011finde olu\u015fturulan function&#8217;lara da route parametresi eklenebilmektedir. \u00d6rne\u011fin;<br \/>\n<code><em><strong>myexample\/<span style=\"color:pink;\">{param1}<\/span>\/<span style=\"color:pink;\">{param2}<\/span><\/strong><\/em><\/code><\/p>\n<p>Tan\u0131mlanan bu route parametre de\u011ferlerini yakalayabilmek i\u00e7in function&#8217;da o parametre isimlerine kar\u015f\u0131l\u0131k parametrelerin tan\u0131mlanmas\u0131 gerekmektedir. \u015e\u00f6yle ki;<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-3.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-3.jpg\" alt=\"Azure Functions Serisi #9 - Http Trigger\" width=\"931\" height=\"105\" class=\"aligncenter size-full wp-image-17279\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-3.jpg 931w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-3-300x34.jpg 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-3-768x87.jpg 768w\" sizes=\"auto, (max-width: 931px) 100vw, 931px\" \/><\/a>\n<\/li>\n<li><strong style=\"color: purple;\">Query String<\/strong><br \/>\nEndpoint&#8217;ler, parametre alarak gizli bir \u015fekilde de\u011fer ta\u015f\u0131yabilen yap\u0131lar olsada yer yer url \u00fczerinden g\u00fcvenlik gerektirmeyen bilgilerimizi herhangi bir gizlili\u011fe gerek duymaks\u0131z\u0131n de\u011fi\u015fkenler ile ta\u015f\u0131mak isteyebiliriz. Bunun i\u00e7in query string yap\u0131s\u0131 kullan\u0131l\u0131r.<\/p>\n<p>Query String yap\u0131lanmas\u0131nda, ne &#8216;Route&#8217; alan\u0131nda s\u00fcsl\u00fc parantez ne de fonksiyonda bir parametre tan\u0131mlamaya gerek vard\u0131r. Direkt olarak url \u00fczerinden tasarlanan query string de\u011ferlerine &#8216;req&#8217; parametresinin &#8216;Query&#8217; property&#8217;si \u00fczerinden eri\u015fim sa\u011flanabilmektedir.<\/p>\n<p>\u00d6rne\u011fin;<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-4.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-4.jpg\" alt=\"Azure Functions Serisi #9 - Http Trigger\" width=\"790\" height=\"97\" class=\"aligncenter size-full wp-image-17284\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-4.jpg 790w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-4-300x37.jpg 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/08\/Azure-Functions-Serisi-9-Http-Trigger-4-768x94.jpg 768w\" sizes=\"auto, (max-width: 790px) 100vw, 790px\" \/><\/a>\n<\/li>\n<li><strong style=\"color: purple;\">Request Body<\/strong><br \/>\nHttp Trigger, client&#8217;tan ald\u0131\u011f\u0131 body ile etkile\u015fimli bir tetikleyici sunmaktad\u0131r. G\u00f6nderilen body Stream olarak &#8216;req.Body&#8217; komutu ile yakalanabilmektedir.<\/p>\n<p>Gelen Stream data&#8217;y\u0131 a\u015fa\u011f\u0131daki gibi parse ederek kullanabilirsiniz.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();\r\n            dynamic data = JsonConvert.DeserializeObject(requestBody);\r\n<\/pre>\n<\/li>\n<\/ul>\n<h3 style=\"color: #e83e8c;\">Http Trigger CORS Ayarlamas\u0131<\/h3>\n<p>Bir endpoint&#8217;i t\u00fcketecek kaynak e\u011fer ki bir taray\u0131c\u0131 ise CORS \u00f6zelli\u011fini ayarlamam\u0131z gerekmektedir. <span style=\"font-size:10px;\">Bknz : <a href=\"https:\/\/www.gencayyildiz.com\/blog\/asp-net-core-uygulamalarinda-corscross-origin-resource-sharing-politikasi-ayarlama\/\" rel=\"noopener noreferrer\" target=\"_blank\">Asp.NET Core Uygulamalar\u0131nda CORS(Cross-Origin-Resource-Sharing) Politikas\u0131 Ayarlama<\/a><\/span><\/p>\n<blockquote style=\"color:green;\"><p><em>CORS; bir g\u00fcvenlik de\u011fil, taray\u0131c\u0131lar i\u00e7in var olan g\u00fcvenli\u011fi gev\u015fetme y\u00f6ntemidir.<\/em><\/p><\/blockquote>\n<p>Azure Function CORS politikalar\u0131n\u0131 ayarlayabilmek i\u00e7in &#8216;local.setting.json&#8217; dosyas\u0131na a\u015fa\u011f\u0131daki ifadeyi eklemeniz gerekmektedir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n  &quot;Host&quot;: {\r\n    &quot;CORS&quot;: &quot;*&quot;\r\n  }\r\n<\/pre>\n<p>Dosyan\u0131n tam hali;<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n{\r\n  &quot;IsEncrypted&quot;: false,\r\n  &quot;Values&quot;: {\r\n    &quot;AzureWebJobsStorage&quot;: &quot;UseDevelopmentStorage=true&quot;,\r\n    &quot;FUNCTIONS_WORKER_RUNTIME&quot;: &quot;dotnet&quot;\r\n  },\r\n  &quot;Host&quot;: {\r\n    &quot;CORS&quot;: &quot;*&quot;\r\n  }\r\n}\r\n<\/pre>\n<p>\u0130lgilenenlerin faydalanmas\u0131 dile\u011fiyle&#8230;<br \/>\nSonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar&#8230;<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, Bu i\u00e7eri\u011fimizde Azure Function trigger t\u00fcrlerinden ilki ve en \u00e7ok kullan\u0131lan\u0131 olan Http Trigger \u00fczerine detayl\u0131ca konu\u015fuyor olaca\u011f\u0131z. Http Trigger Nedir? Http Trigger, taraf\u0131m\u0131za verdi\u011fi endpointler arac\u0131l\u0131\u011f\u0131yla tetiklenebilir bir fonksiyon \u00e7e\u015fididir. Http Trigger&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":17011,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3121],"tags":[3686,3692,3661,3691,3718,3716,3717,3715],"class_list":["post-17256","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure","tag-azure-function","tag-azure-function-http-trigger","tag-azure-functions","tag-http-trigger","tag-http-trigger-cors","tag-http-trigger-query-string","tag-http-trigger-request-body","tag-http-trigger-route"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/17256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=17256"}],"version-history":[{"count":31,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/17256\/revisions"}],"predecessor-version":[{"id":17292,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/17256\/revisions\/17292"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/17011"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=17256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=17256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=17256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}