<?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: Adetoye Anointing</title>
    <description>The latest articles on DEV Community by Adetoye Anointing (@yorubad-dev).</description>
    <link>https://dev.to/yorubad-dev</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%2F886675%2Fea4004d8-be02-444d-bf9c-74cbf03bab17.jpeg</url>
      <title>DEV Community: Adetoye Anointing</title>
      <link>https://dev.to/yorubad-dev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yorubad-dev"/>
    <language>en</language>
    <item>
      <title>Setting Up A PostgreSQL Database on AWS: A Step-by-Step Guide to Generate a Service Connection String</title>
      <dc:creator>Adetoye Anointing</dc:creator>
      <pubDate>Thu, 11 Jan 2024 19:50:34 +0000</pubDate>
      <link>https://dev.to/yorubad-dev/setting-up-a-postgresql-database-on-aws-a-step-by-step-guide-to-generate-your-services-connection-string-2bap</link>
      <guid>https://dev.to/yorubad-dev/setting-up-a-postgresql-database-on-aws-a-step-by-step-guide-to-generate-your-services-connection-string-2bap</guid>
      <description>&lt;p&gt;If you're reading this, you've probably struggled with how to set up a Postgres database on AWS and generate a connection for usage in your application. &lt;/p&gt;

&lt;p&gt;Perhaps you are like me, highly focused on backend development, and need to add the connection in your &lt;code&gt;.env&lt;/code&gt; file. You're probably under a lot of mental strain because you just built or are about to build a $16 per month database instance and AWS wants you to utilize 101% of your brain, making it difficult to connect to the database instance.&lt;/p&gt;

&lt;p&gt;This article provides a step-by-step guide on how to create, configure, and connect to your database instance on AWS. The knowledge provided can be applied to a wide range of scenarios.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;p&gt;This guide will walk you through the steps of creating a free database instance on AWS. However, it is important to note that you will incur charges for using it, so it's advisable to delete the instance when you are not actively using it.&lt;/p&gt;

&lt;p&gt;If you already know how to create and configure an instance, skip to the &lt;code&gt;connection string generation&lt;/code&gt; section for help with connection.&lt;/p&gt;

&lt;p&gt;All highlighted fields and sections in the images of this article are considered important to take note of.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Get Started
&lt;/h2&gt;

&lt;p&gt;First, navigate to Amazon AWS and create/log in to your account.&lt;/p&gt;

&lt;p&gt;It can be done using the following link : &lt;a href="https://aws.amazon.com/" rel="noopener noreferrer"&gt;Amazon AWS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2udjr7wakuxylai8qcyc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2udjr7wakuxylai8qcyc.png" alt="Amazon AWS Landing Page" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Navigate To The Resources For Creating A Database
&lt;/h3&gt;

&lt;p&gt;In the console's home menu, we select the 'RDS' section as it manages resources and instances for relational databases. The abbreviation stands for 'Relational Database Service'.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa73mtit2q7zuoftns38r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa73mtit2q7zuoftns38r.png" alt="RDS Selection Field" width="800" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Select A Creation Method
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;selection method&lt;/code&gt; is choosing between setting up your instance yourself or letting Amazon's service take the wheel for you.&lt;/p&gt;

&lt;p&gt;For this tutorial, we will select the &lt;code&gt;standard create&lt;/code&gt; option as it provides more flexibility to customize.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8oe904l39hs9lt8rpsfg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8oe904l39hs9lt8rpsfg.png" alt="selection method fields" width="800" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Database Engine Type Selection
&lt;/h3&gt;

&lt;p&gt;In this article, we will be using Postgres as our database engine, so naturally, it should be our top choice.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxjym9ojxdz84zoeo0qw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxjym9ojxdz84zoeo0qw.png" alt="postgres engineer selected" width="800" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After selecting the engine type, we will choose a free tier template for the tutorial. This will also prevent us from getting charged heavily in case we forget to delete the resources.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fianazv9w2c6ybf32g7dw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fianazv9w2c6ybf32g7dw.png" alt="free tier selection" width="774" height="569"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Important Database Setting
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Name The DB instance identifier
&lt;/h4&gt;

&lt;p&gt;It is important to note that adding a database instance identifier that is descriptive is very crucial to identify instance and it should be done for your ease&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl2nccl5ui0tb7c8r1s8d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl2nccl5ui0tb7c8r1s8d.png" alt="descriptive instance identifier" width="761" height="223"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Credential Settings
&lt;/h4&gt;

&lt;p&gt;This simply involves adding the database username and password that should be tied to the instance on creation&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvjujvubxqx0413ihxv0k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvjujvubxqx0413ihxv0k.png" alt="credenctial setting" width="762" height="579"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;It is essential to create a unique password for the database instance instead of relying on the auto-generated password field for easy recall.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Database Instance Configuration
&lt;/h3&gt;

&lt;p&gt;For the final step of the first phase (creation of Database instance), we will add the most important.&lt;/p&gt;

&lt;p&gt;You need to scroll down until you see a section labeled &lt;code&gt;Additional configuration&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This section holds the field that will be used to name our database and it is very important because without it there will be no database created and this part is missed a lot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fftnh6fkht2r8i393t4fr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fftnh6fkht2r8i393t4fr.png" alt="naming the database resources" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the entire configuration is complete, your billing should match this if you have done everything correctly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foiprq2pp3tua5b40ehzo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foiprq2pp3tua5b40ehzo.png" alt="billing for database instance" width="773" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then proceed to hit the create database button. &lt;/p&gt;

&lt;p&gt;It will take approximately 5-10 minutes or less to create. Once completed, we can proceed to the next phase.&lt;/p&gt;

&lt;h3&gt;
  
  
  Connection String Generation
&lt;/h3&gt;

&lt;p&gt;This is the second phase, and I must acknowledge that it is the trickiest part of it all.&lt;/p&gt;

&lt;p&gt;The format for putting together an Amazon AWS Postgres database connection string together is simply :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;postgres://&amp;lt;username&amp;gt;:&amp;lt;password&amp;gt;@&amp;lt;database_endpoint&amp;gt;/&amp;lt;database_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;username = &lt;code&gt;master username&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;password = &lt;code&gt;initially added password&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;database_endpoint = &lt;code&gt;endpoint generated by AWS&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;database_name = &lt;code&gt;name given to database on creation&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To begin with, please navigate to the newly created resources. If you're already there, scroll down a bit and you'll find the database endpoint.&lt;/p&gt;

&lt;p&gt;This is a crucial component in generating the connection string.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkzbcv3js0oqonf4kdc7p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkzbcv3js0oqonf4kdc7p.png" alt="database instance endpoint" width="550" height="700"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Afterward, click on the &lt;code&gt;Configuration&lt;/code&gt; section in the newly created instance&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7pvecku7pg292qzsk2qm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7pvecku7pg292qzsk2qm.png" alt="configution section" width="800" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Get the username, password, and database name from the &lt;code&gt;Configuration&lt;/code&gt; section when you scroll slightly downward&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcy75v5asvtyoynon5l8t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcy75v5asvtyoynon5l8t.png" alt="configuration information" width="800" height="429"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have constructed the connection string, can we start working on the database?&lt;/p&gt;

&lt;p&gt;"The answer is no."&lt;/p&gt;

&lt;p&gt;Before putting the database instance to good use, one additional configuration must be done for full remote access.&lt;/p&gt;

&lt;h3&gt;
  
  
  Access Configuration
&lt;/h3&gt;

&lt;p&gt;This involves declaring access to the database instance as part of a security measure to prevent unwanted connections and access to resources.&lt;/p&gt;

&lt;p&gt;To accomplish this, you will need to add an inbound rule to the database instance.&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;Connectivity &amp;amp; security&lt;/code&gt; section, we will click on the link in the &lt;code&gt;VPC security groups&lt;/code&gt; field&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi7n5fqy9gk2rlejnrjb5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi7n5fqy9gk2rlejnrjb5.png" alt="security group" width="800" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's navigate to the &lt;code&gt;Security group ID&lt;/code&gt; of the database instance to make modifications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fclct06cq4o68wg3ixkfo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fclct06cq4o68wg3ixkfo.png" alt="security group ID" width="800" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click the &lt;code&gt;edit inbound rules&lt;/code&gt; button&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcxg2vc0hme2hqahuf1yf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcxg2vc0hme2hqahuf1yf.png" alt="edit inbound rule" width="800" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on &lt;code&gt;Add rules&lt;/code&gt; below the already predefined rules and add two rules&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F304gxs7wykyppebugdtc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F304gxs7wykyppebugdtc.png" alt="adding rules" width="800" height="267"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;highlighted red = &lt;code&gt;protocol type&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;highlighted blue = &lt;code&gt;the database port [which by default is "5432"]&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;highlighted cyan = &lt;code&gt;connection source&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Save these rules put in place and configured. You are good to connect to your database on Amazon RDS and have fun with it.&lt;/p&gt;

&lt;p&gt;Note that the &lt;strong&gt;highlighted green&lt;/strong&gt; indicates a security warning. If possible, please provide the IP address of your service instance or local machine to avoid this security flag that might eventually turn into a security vulnerability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;with this guide, you should be able to set up a Postgres database on Amazon AWS, configure and have it connected to your local machine or web server using the connection string.&lt;/p&gt;

&lt;p&gt;I hope this article was insightful and that you find It helpful &lt;/p&gt;

&lt;p&gt;Pro tip: Avoid unnecessary charges by shutting down and deleting unused AWS instances. &lt;/p&gt;

&lt;p&gt;Thank you for reading, drop a comment if you have a question, and have fun :) &lt;/p&gt;

</description>
      <category>aws</category>
      <category>postgres</category>
      <category>database</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Handling Dynamic API Response In Go</title>
      <dc:creator>Adetoye Anointing</dc:creator>
      <pubDate>Mon, 01 Jan 2024 20:29:11 +0000</pubDate>
      <link>https://dev.to/yorubad-dev/handling-dynamic-api-response-in-go-640</link>
      <guid>https://dev.to/yorubad-dev/handling-dynamic-api-response-in-go-640</guid>
      <description>&lt;p&gt;A Go developer working on a service that requires a third-party API integration and that integration has a webhook or something similar that returns a changing response body structure depending on the event sent to and through the hook.&lt;/p&gt;

&lt;p&gt;A lot of people do not essentially know how to handle this scenario in Go at least using the gracious and glorious &lt;strong&gt;JSON&lt;/strong&gt; package to handle something simple yet overly complicated task in Go.&lt;/p&gt;

&lt;p&gt;Today, we will have a walkthrough on handling dynamic API responses in Go using the &lt;code&gt;JSON&lt;/code&gt; package.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;p&gt;It is crucial to understand that dynamic API responses take different forms, some are events triggered in response to an activity in the service. Whether it is a FinTech API using a webhook to notify the system of an event or a user triggering a notification to an admin dashboard on a specific event.&lt;/p&gt;

&lt;p&gt;These dynamic APIs hold a means of identification that can be used to identify them and separate them into their different predefined structure in most cases.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;let's get into the fun part of this article [the coding part]&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  To get started with this tutorial, you will need:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Go installed and set up&lt;/li&gt;
&lt;li&gt;An IDE or test editor &lt;/li&gt;
&lt;li&gt;Practical Knowledge of Go&lt;/li&gt;
&lt;li&gt;Postman&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Initial stage [ Setup your project repo ]
&lt;/h3&gt;

&lt;p&gt;Open the terminal and set up our project repo using the command below. (&lt;em&gt;This of course works on Linux and macOS&lt;/em&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir Documents/dynamic-API &amp;amp;&amp;amp; touch Documents/dynamic-API/
main.go &amp;amp;&amp;amp; code Documents/dynamic-API
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go mod init [your-github-name]/handling-dynamic-api
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create our main function and setup for development.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import "log/slog"


func main() {
    // setup a logger using slog
    logger := slog.New(slog.NewTextHandler(os.Stdout, nil))

    logger.Info("Hello Terminal 👋", "user", os.Getenv("USER"))

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Build the function that handles the API response for the service.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func HandleDynamicAPI(l *slog.Logger) http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {
        l.Info("This API is connected", "user", os.Getenv("USER"))
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function will hold the entire logic that handles the response from the webhook.&lt;br&gt;
Since we are handling this without a third-party library or framework, we will be using the built-in Go &lt;strong&gt;http&lt;/strong&gt; library to handle this bit which will require importing &lt;code&gt;net/http&lt;/code&gt; while also defining a logger of type &lt;code&gt;*slog.Logger&lt;/code&gt; as an argument to the &lt;strong&gt;HandleDynamicAPI&lt;/strong&gt; function&lt;/p&gt;

&lt;p&gt;&lt;em&gt;random fun fact: if you are not a VIM / Nano user, you might not need to worry about importation cause your text editor probably have it handled&lt;/em&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Hence; your current code should look something like this
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "log/slog"
    "net/http"
)


func main() {
    // setup a logger using slog
    logger := slog.New(slog.NewTextHandler(os.Stdout, nil))

    logger.Info("Hello Terminal 👋", "user", os.Getenv("USER"))

}

func HandleDynamicAPI(l *slog.Logger) http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {
        l.Info("This API is connected", "user", os.Getenv("USER"))

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

&lt;/div&gt;

&lt;h3&gt;
  
  
  Catch And Identify The Response Event Or Identifier &lt;em&gt;(in case of an API with events or identifiers)&lt;/em&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Event Identifier Structure
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//this will be used to identify the event type
//
//We care about just the event head
type eventIdentfier struct {
    Event string `json:"event"`
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Logic To Catch And Identify Event
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func HandleDynamicAPI(l *slog.Logger) http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {
        l.Info("This API is connected", "user", os.Getenv("USER"))

        var (
            eventIdentfier    eventIdentfier
            jsonData          json.RawMessage
        )

        if err := json.NewDecoder(r.Body).Decode(&amp;amp;jsonData); err != nil {
            l.Error("error decoding json response", "error context", err)
            return
        }

        if err := json.Unmarshal(jsonData, &amp;amp;eventIdentfier); err != nil {
            l.Error("error unmarshalling json data message", "error context", err)
            return
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;What the written code above does is it catches the API response body data and decodes it into the &lt;code&gt;jsonData&lt;/code&gt; variable which is a type of &lt;code&gt;json.RawMessage&lt;/code&gt; and that &lt;strong&gt;jsonData&lt;/strong&gt; value is &lt;strong&gt;unmarshalled&lt;/strong&gt; into the &lt;code&gt;eventIdentifier&lt;/code&gt; variable to be used in the later stage of development.&lt;/p&gt;

&lt;p&gt;How the &lt;code&gt;json.RawMessage&lt;/code&gt; works are it delays json decoding of the body making it flexible to use for re-unmarshalling as I will call it and in our case used for event identification and eventually decoding into a defined json structure.&lt;/p&gt;
&lt;h3&gt;
  
  
  Using Event To Identify Execution Case
&lt;/h3&gt;

&lt;p&gt;In this part, we will be going deeper into Go using control flow to execute logic and many cases functions after identification of the event that should be executed.&lt;/p&gt;

&lt;p&gt;firstly, we want to know what the event value will be, which will be used to handle the control flow of the program.&lt;br&gt;
These are usually found in the API / webhook documentation and our case we are using paystack.&lt;/p&gt;

&lt;p&gt;For information about Paystack's webhooks, check out their API documentation and visit &lt;a href="https://paystack.com/docs/payments/webhooks/" rel="noopener noreferrer"&gt;Paystack Webhook URL&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The event we will simulate for this tutorial is :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Payment Request Pending &lt;/li&gt;
&lt;li&gt;Payment Request Successful&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Looking at the response structure provided by paystack we can easily create a struct and fill out the fields needed but in our case due to some reason unknown to me for the fun of it; I will be using the entire field :).&lt;/p&gt;
&lt;h4&gt;
  
  
  Response Body Data Structure For Unmarshalling
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type paymentPending struct {
    Event string `json:"event"`
    Data  struct {
        ID               int       `json:"id"`
        Domain           string    `json:"domain"`
        Amount           int       `json:"amount"`
        Currency         string    `json:"currency"`
        DueDate          any       `json:"due_date"`
        HasInvoice       bool      `json:"has_invoice"`
        InvoiceNumber    any       `json:"invoice_number"`
        Description      string    `json:"description"`
        PdfURL           any       `json:"pdf_url"`
        LineItems        []any     `json:"line_items"`
        Tax              []any     `json:"tax"`
        RequestCode      string    `json:"request_code"`
        Status           string    `json:"status"`
        Paid             bool      `json:"paid"`
        PaidAt           any       `json:"paid_at"`
        Metadata         any       `json:"metadata"`
        Notifications    []any     `json:"notifications"`
        OfflineReference string    `json:"offline_reference"`
        Customer         int       `json:"customer"`
        CreatedAt        time.Time `json:"created_at"`
    } `json:"data"`
}

type paymentSuccessful struct {
    Event string `json:"event"`
    Data  struct {
        ID            int       `json:"id"`
        Domain        string    `json:"domain"`
        Amount        int       `json:"amount"`
        Currency      string    `json:"currency"`
        DueDate       any       `json:"due_date"`
        HasInvoice    bool      `json:"has_invoice"`
        InvoiceNumber any       `json:"invoice_number"`
        Description   string    `json:"description"`
        PdfURL        any       `json:"pdf_url"`
        LineItems     []any     `json:"line_items"`
        Tax           []any     `json:"tax"`
        RequestCode   string    `json:"request_code"`
        Status        string    `json:"status"`
        Paid          bool      `json:"paid"`
        PaidAt        time.Time `json:"paid_at"`
        Metadata      any       `json:"metadata"`
        Notifications []struct {
            SentAt  time.Time `json:"sent_at"`
            Channel string    `json:"channel"`
        } `json:"notifications"`
        OfflineReference string    `json:"offline_reference"`
        Customer         int       `json:"customer"`
        CreatedAt        time.Time `json:"created_at"`
    } `json:"data"`
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;declare a variable of both defined structures in the existing variable list &lt;/p&gt;

&lt;p&gt;&lt;code&gt;paymentPending    paymentPending&lt;br&gt;
paymentSuccessful paymentSuccessful&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After defining the struct and declaring the variables, we will then proceed to write out the control flow and implement the logic for the program&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        switch eventIdentfier.Event {
        case "paymentrequest.pending":
            l.Info("payment pending hook event", "response event title", eventIdentfier.Event)

            if err := json.Unmarshal(jsonData, &amp;amp;paymentPending); err != nil {
                l.Error("error marshalling pending payment data", "error context", err)
                return
            }

            if err := json.NewEncoder(w).Encode(map[string]any{"event type": paymentPending.Event, "amount": paymentPending.Data.Amount}); err != nil {
                l.Error("error encoding data to send as response", "error context", err)
                return
            }
            w.Header().Add("Content-Type", "application/json")

            l.Info("pending response data unmarshalled successfully", "pending ID", paymentPending.Data.ID, "pending amount", paymentPending.Data.Amount)
        case "paymentrequest.success":
            l.Info("payment successful hook event", "response event title", eventIdentfier.Event)

            if err := json.Unmarshal(jsonData, &amp;amp;paymentSuccessful); err != nil {
                l.Error("error marshalling successful payment data", "error context", err)
                return
            }

            if err := json.NewEncoder(w).Encode(map[string]string{"event type": paymentSuccessful.Event}); err != nil {
                return
            }
            w.Header().Add("Content-Type", "application/json")

            l.Info("success response data unmarshalled successfully", "success ID", paymentSuccessful.Data.ID, "success amount", paymentSuccessful.Data.Amount)
        default:
            l.Info("no event type found", "response event title", eventIdentfier.Event)
            w.WriteHeader(http.StatusInternalServerError)
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above retrieves the event from the variable named &lt;code&gt;eventIdentifier&lt;/code&gt;. It then uses the &lt;code&gt;switch&lt;/code&gt; control flow to determine which API event has been passed to the endpoint. After identifying the API event, the data is decoded into the defined struct. Finally, an API response is returned with the required specified data.&lt;/p&gt;

&lt;p&gt;There are instances where data is handled differently, and it doesn't involve returning a few selected fields as shown in the example above. Such cases include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Storing the data in a database&lt;/li&gt;
&lt;li&gt;Using the data for manipulation purposes&lt;/li&gt;
&lt;li&gt;Utilizing the data for verifying a triggered action, and so on.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;focusing on the basics is crucial for building a strong foundation to tackle more advanced projects.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Plug In The Function To An Endpoint
&lt;/h3&gt;

&lt;p&gt;Plugging a function into an endpoint is easily one of the first you learn while studying Go and I am counting that this won't be the tricky part.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Plug in the function to the http handler using this line&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;http.HandleFunc("/dynamic-hook", HandleDynamicAPI(logger))&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;setup service listener
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;go log.Fatal(http.ListenAndServe(":3000", nil))&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;These should be done in the main function, hence; the main function should look like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func main() {
    // setup a logger using slog
    logger := slog.New(slog.NewTextHandler(os.Stdout, nil))

    logger.Info("Hello Terminal 👋", "user", os.Getenv("USER"))

    http.HandleFunc("/dynamic-hook", HandleDynamicAPI(logger))

    go log.Fatal(http.ListenAndServe(":3000", nil))
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Running, Testing And Finishing
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Run Go Server&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We run the program with our gracious Go command in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go run main.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Test Endpoint And Simulate Webhook&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To do this we have to copy the webhook json data and pass it to the designated endpoint using Postman&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;paymentrequest.success event response&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd6be5uad2be8xaghp5y0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd6be5uad2be8xaghp5y0.png" alt="paymentrequest.success event response" width="800" height="491"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;paymentrequest.pending event response&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fejlrp7fe8s061c1hfenq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fejlrp7fe8s061c1hfenq.png" alt="paymentrequest.pending event response" width="800" height="486"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;You should have a basic understanding of how to handle dynamic API response bodies, including use cases and the importance of the &lt;code&gt;json&lt;/code&gt; package in Go for handling responses.&lt;/p&gt;

&lt;p&gt;I hope you found this tutorial helpful. &lt;/p&gt;

&lt;p&gt;Have fun practicing :)&lt;/p&gt;

&lt;h3&gt;
  
  
  Link To The Entire Code Sample
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/KingDaemonX/dynamic-API-handling" rel="noopener noreferrer"&gt;Handling Dynamic API Response&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>json</category>
      <category>api</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
