<?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: Amorto Goon</title>
    <description>The latest articles on DEV Community by Amorto Goon (@mortogn).</description>
    <link>https://dev.to/mortogn</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%2F1090060%2F62883f7f-93be-479e-a225-67bc172f6919.jpg</url>
      <title>DEV Community: Amorto Goon</title>
      <link>https://dev.to/mortogn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mortogn"/>
    <language>en</language>
    <item>
      <title>Go + Echo: The Simple Way to Build a Web Server</title>
      <dc:creator>Amorto Goon</dc:creator>
      <pubDate>Sun, 22 Mar 2026 14:14:51 +0000</pubDate>
      <link>https://dev.to/mortogn/go-echo-the-simple-way-to-build-a-web-server-1eja</link>
      <guid>https://dev.to/mortogn/go-echo-the-simple-way-to-build-a-web-server-1eja</guid>
      <description>&lt;p&gt;Building a performant API shouldn't feel like a chore. If you're looking for a simple language that is fun and performant, look no further than go. There are a lot of frameworks for GO but today we will be choosing Echo.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;em&gt;TLDR&lt;/em&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Project Setup:&lt;/strong&gt; Initializing a Go module&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Echo Basic:&lt;/strong&gt; Creating echo instance for route handling with v5&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Routing:&lt;/strong&gt; Handling Get Request&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;em&gt;Before we begin&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;In this guide, we will not go over how to install and setup go. It's assumed you already have go installed and configured.&lt;/p&gt;

&lt;p&gt;We are also assuming you know basic Go syntax and how to create a simple hello word program.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Project setup
&lt;/h3&gt;

&lt;p&gt;To start, we need to initialize a go module in our current working directory. Once you are in a folder where you'd like to build this application, initialize module.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go mod init myserver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ideally, you'd put your source code location, for example &lt;code&gt;github.com/[your_username]/[repo_name]&lt;/code&gt; but for the sake of simplicity we will be using &lt;code&gt;myserver&lt;/code&gt; instead.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Echo Basic
&lt;/h3&gt;

&lt;p&gt;To use Echo as our framework, we need to create a main package first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1.&lt;/strong&gt; Create a file and name it &lt;code&gt;main.go&lt;/code&gt;. We can also run the following command to create the file. Make sure we are still on our working directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;main.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2.&lt;/strong&gt; Inside main file let's create a simple main function and print hello world.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello World!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can run our application and see &lt;code&gt;Hello World!&lt;/code&gt; printed on our terminal.&lt;/p&gt;

&lt;p&gt;To run this application,&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3.&lt;/strong&gt; Now that we have a basic working application, we can bring in Echo to create our server.&lt;/p&gt;

&lt;p&gt;To install Echo,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go get github.com/labstack/echo/v5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4.&lt;/strong&gt; After installing Echo successfully we can start creating our API.&lt;/p&gt;

&lt;p&gt;After this guide, we want to visit &lt;code&gt;http://localhost:4000/hello&lt;/code&gt; and get a json response similar to this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Hello World!"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To achieve our goal, let's start adding changes to our &lt;code&gt;main.go&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

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

&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"net/http"&lt;/span&gt; &lt;span class="c"&gt;// import net/http for HTTP status codes&lt;/span&gt;

    &lt;span class="s"&gt;"github.com/labstack/echo/v5"&lt;/span&gt; &lt;span class="c"&gt;//import echo v5&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// Create a new Echo instance&lt;/span&gt;
    &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;echo&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;New&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c"&gt;// Define a route for GET requests to "/hello"&lt;/span&gt;
    &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GET&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/hello"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;echo&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusOK&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;"message"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Hello World!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;

    &lt;span class="c"&gt;// Start the server on port 4000 and log any errors that occur&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;":4000"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Logger&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"failed to start server"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have made quite a bit of changes here. I have made to sure to add comments so we can understand what each chunk of code does even before you get to this line. However, let's a still dive a bit deeper.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Initializing Echo: Before we can use any of the functionality that echo provides us, we have to initialize it. We can do so by using &lt;code&gt;echo.New()&lt;/code&gt; and importing the echo package &lt;code&gt;github.com/labstack/echo/v5&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get request: In Echo, if we want to create an endpoint we can do so by using the variable where we stored our echo instance. Similarly we can also use &lt;code&gt;e.POST()&lt;/code&gt;, &lt;code&gt;e.PUT()&lt;/code&gt;, &lt;code&gt;e.DELETE()&lt;/code&gt; etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Returning JSON: To make our endpoint return a json response we have to use &lt;code&gt;c.JSON()&lt;/code&gt;. It accepts two parameters, one is the http status code. You might have noticed that we are using go http package to return the status code, you can also use &lt;code&gt;200&lt;/code&gt; instead of using &lt;code&gt;http.StatusOK&lt;/code&gt;. The other parameter is our response data. To return a JSON response, we are using map. We can return all sorts of data through the second parameter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Logging: Things can go south anytime, that's why we are making sure we are printing any errors that may occur, making things easy for debugging in future.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Starting the server: To Start the server, we used &lt;code&gt;e.Start()&lt;/code&gt;. Since we were planning to start our server on port 4000. We can pass &lt;code&gt;:4000&lt;/code&gt; through &lt;code&gt;e.Start()&lt;/code&gt; parameter.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just like that, we now understand how to build an Echo server and a simple explanation of all the functions we used.&lt;/p&gt;

&lt;p&gt;But we are not done yet..&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Step 5:&lt;/em&gt; Now we have to test our API.
&lt;/h3&gt;

&lt;p&gt;Run our go application using,&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;If the application is running successfully, open your browser and visit &lt;code&gt;http://localhost:4000/hello&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We should see json response saying hello to the entire world.&lt;/p&gt;

&lt;p&gt;And that's it. You have successfully initialized a go module, initialized echo and created a basic performant custom api endpoint.&lt;/p&gt;

&lt;p&gt;Thank you everyone for reading! This is my first article on dev.to. I'd love to hear your feedback, or any tips you have for a new writer. Happy coding!&lt;/p&gt;

</description>
      <category>go</category>
      <category>backend</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
