<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Marudut Try Putra Marpaung on Medium]]></title>
        <description><![CDATA[Stories by Marudut Try Putra Marpaung on Medium]]></description>
        <link>https://medium.com/@maruduttryputra?source=rss-d4faf1ce56f6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*2C2kH1s7JQYnqazb.</url>
            <title>Stories by Marudut Try Putra Marpaung on Medium</title>
            <link>https://medium.com/@maruduttryputra?source=rss-d4faf1ce56f6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 23:58:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@maruduttryputra/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Go — REST API Simple Tutorial]]></title>
            <link>https://medium.com/@maruduttryputra/go-rest-api-simple-tutorial-dbe6c5c30033?source=rss-d4faf1ce56f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbe6c5c30033</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Marudut Try Putra Marpaung]]></dc:creator>
            <pubDate>Wed, 26 Dec 2018 02:51:17 GMT</pubDate>
            <atom:updated>2018-12-26T05:13:03.649Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*bqiDv-5vD-IEgBdbJ4iUTQ.jpeg" /></figure><p>Go — REST API Simple Tutorial</p><p><strong>Prerequisite</strong></p><p>Before you take deeper on this tutorial, it will good idea if you take a look first into Data type in GO, having standard knowledge with JSON, API REST and SQL syntax</p><p><strong>Intro</strong></p><p><em>REST</em>, as we know it stands for a architecture of communication method that used HTTP protocol in data exchange, this is implementation of API(Application Programming Interface) that allowed different systems able to communicate despite they used different system, lets say A used PHP and the other used GO or Java.</p><p><em>JSON</em>, stands for JavaScript Object Notation. it is a light format data that easy to be used. The plus is easy to create, modify and generated by computer quickly. Please take a look on <a href="https://www.json.org/json-id.html">https://www.json.org/json-id.html</a> for further informations</p><p><em>SQL</em>, stands for Structure Query Language that used to access data in relational database. This language is a standard that used to DDL and DML on database.</p><p><strong>Software Design</strong></p><p>When we create/develop a software, we have to care about designing a software. It will cost much time and really painful 😐 if we didn’t aware about the architect that should be covered about business and data growth or even the changes that could be happen during developing the software</p><p>This is my first attempt to write a GO code and touch “create and update” data with SQL, in this case i choose MySQL, because i think this system is easy to learned. Please don’t expect high on the quality of the architect, so far i just separate the logic, model and the util. That will be lovely if you guys give a good input to improve my erudition in future.</p><p><strong>Folder Structure</strong></p><p>I wrote GO code for calculating Park Charge, Generally i divided the file based on usage and put them in a package, please check out the package term in GO. Dividing them in to several folders/packages. conf folder will be used to store any configuration such as const, database connection, etc. Controller folder will handle the logic, model to touch the database query, util for code utilization and last is main.go file to run the server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*GveiSDRKoSzGGAgkFdsHug.png" /></figure><p>in this mini project there will be 3 endpoints :</p><ol><li>POST /parking : used to create a new resource on database, lets say that this function will be used by user to register / entry into the park system from user perspective. This endpoint will return registration id in case everything is going well</li><li>PATCH /parking : used for user to pay the park charge, in this article i write the const PARK_PRICE = 3000 per hour and saved it in conf file</li><li>parking/duration/ : This one is free from endpoint method, there is no excuse i set this free, LOL, it will returned the data vehicle that already paid in give range time</li></ol><p><strong>MySQL Query</strong></p><p>I developed this project using MySQL database, firstly lets create database and execute this tables query :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c5ae2d591c167d3100395dae9364baf/href">https://medium.com/media/3c5ae2d591c167d3100395dae9364baf/href</a></iframe><p><strong>Conf</strong></p><p>This file contains const file and database connection, maybe next will be added according to business need such as Third party’s URL, and bla bla bla</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce60754f56eb37bf46a743b0d2bdce1a/href">https://medium.com/media/ce60754f56eb37bf46a743b0d2bdce1a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05e9b1f8218c6322cbc8e17def9cac86/href">https://medium.com/media/05e9b1f8218c6322cbc8e17def9cac86/href</a></iframe><p><strong>Main File</strong></p><p>This file will be used to run the application,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3fb686ae6ef2656a42ac119a188f2f2/href">https://medium.com/media/a3fb686ae6ef2656a42ac119a188f2f2/href</a></iframe><p>as we can see the figure above, the server will start on port:9000 and listening 3 endpoints that already mentioned before.</p><p><strong>Controller</strong></p><p>This folder contains the file that will be handle the logic, so far the logic step was get param for given url/endpoint, query into database using model and operate / manipulate the data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4fc65fc7acbf081b610981637e788c48/href">https://medium.com/media/4fc65fc7acbf081b610981637e788c48/href</a></iframe><p><strong>Model</strong></p><p>The aim of this file is connect and select data from database/MySQL. Functions within will be called by controller and passed back to controller.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08b6f117539c5924f0cb72029fab2589/href">https://medium.com/media/08b6f117539c5924f0cb72029fab2589/href</a></iframe><p><strong>Util</strong></p><p>This file was used to code utilization, in this project the Response configuration will be placed into this package/folder. The Response.go will be used by controller to passed the response/result to the client.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6693534fc54a29654712c111416527a2/href">https://medium.com/media/6693534fc54a29654712c111416527a2/href</a></iframe><p>here the result</p><ol><li>POST parking : this one will generate registration id, i took timestamps anyway</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fjrtM43-GpWImz1FYnB7aA.png" /><figcaption>Register</figcaption></figure><p>2. PATCH parking : will produce duration and the price</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kdAQee_h1wHmBDpPVZ-0Mg.png" /><figcaption>paid</figcaption></figure><p>3. Get paid list</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zozK34AKWLkTtwGfBiv56Q.png" /><figcaption>get list</figcaption></figure><p><strong>Conclusions</strong></p><ol><li>When you want to develop a software, think about the design pattern and separate them by its function/usage</li><li>If you are just enter to learn about GO, sometimes it’s difficult to troubleshoot, but later it will be fun 😆</li><li>Be careful on data type in GO, unlike PHP, GO is like JAVA that only allowed same data type to be operated</li></ol><p><strong>Improvement</strong></p><p>as i mentioned before this is my first time in GO 🐵 there will be things that need to be added in this code, for example I still print out the error on the server side, not return the response to client which is the client will not know whats going on if the error thrown 🙌, maybe next time will be improved.</p><p>Next i will try to add middleware, i will pick the JWT on, see you later, if you have any concern, fell free to let me know. Thank You</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbe6c5c30033" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>