Gin simplifies the process of building high-performance web applications with Golang. In this guide, we’ll walk through creating your first Gin application step by step.
Written by
Şuayb Şimşek
Backend-focused fullstack developer sharing practical notes on Spring Boot, security, microservices, and cloud-native architecture.
Get practical backend + fullstack notes when new articles are published.
Social
🌟 What you'll learn
In this section, we clarify What you'll learn and summarize the key points you will apply in implementation.
How to initialize a minimal Gin project structure.
How to build and expose your first JSON endpoint.
How to run and validate the service locally before adding business logic.
📋 Prerequisites
📋 Before starting, ensure you have the following:
🔧 Golang 1.17+ installed
🗍 A text editor or IDE (e.g., Visual Studio Code, GoLand, or Vim)
🛠️ Step 1: Set Up Your Gin Project
You can set up your first Gin project by following these steps:
Initialize a Go Module
BASH
mkdir gin-first-app
cd gin-first-app
go mod init gin-first-app
Install Gin
BASH
go get -u github.com/gin-gonic/gin
🛠️ Step 2: Writing Your First Endpoint
Let’s write a simple endpoint to say hello:
Create a file named main.go with the following content:
GOmain.go
package main
import (
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.GET("/hello", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "Hello, Gin!",
})
})
r.Run() // Listen and serve on 0.0.0.0:8080
}
▶️ Step 3: Run the Application
In this section, we clarify Step 3: Run the Application and summarize the key points you will apply in implementation.
Open a terminal in the project folder.
Execute the following command to run your application:
BASH
go run main.go
Access the endpoint at:
FILENAME
http://localhost:8080/hello
Response:
JSONconfig.json
{
"message": "Hello, Gin!"
}
🏁 Conclusion
You now have a practical Gin - First Application implementation with a clear, production-friendly structure. As a next step, adapt configuration and tests to your own domain, then validate behavior under realistic traffic and failure scenarios.