<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Elias Butting</title>
    <description>The latest articles on DEV Community by Elias Butting (@eliasbutting).</description>
    <link>https://dev.to/eliasbutting</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F105965%2Facc80e17-a103-4ce4-afa7-5ac761f25f35.jpg</url>
      <title>DEV Community: Elias Butting</title>
      <link>https://dev.to/eliasbutting</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/eliasbutting"/>
    <language>en</language>
    <item>
      <title>Best practices querying APIs via cloud functions</title>
      <dc:creator>Elias Butting</dc:creator>
      <pubDate>Wed, 22 Jan 2020 12:33:38 +0000</pubDate>
      <link>https://dev.to/eliasbutting/best-practices-querying-apis-via-cloud-functions-2j0p</link>
      <guid>https://dev.to/eliasbutting/best-practices-querying-apis-via-cloud-functions-2j0p</guid>
      <description>&lt;p&gt;Im currently working on a little side project where I want to query an api via cloud functions.&lt;/p&gt;

&lt;p&gt;The API has several endpoints, say "Users" and "Posts".&lt;/p&gt;

&lt;p&gt;Do I create one function for each endpoint? ie:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="nf"&gt;getUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Userdata&lt;/span&gt;
&lt;span class="nf"&gt;getPost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Postdata&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OR do I create one single function that chooses the endpoint via a given paramenter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="nf"&gt;getApiData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Userdata&lt;/span&gt;
&lt;span class="nf"&gt;getApiData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;post&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Postdata&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Are there any best practices? What are the pros and cons? How do you do it?&lt;/p&gt;

</description>
      <category>serverless</category>
      <category>beginners</category>
      <category>help</category>
    </item>
  </channel>
</rss>
