RESTful API with Go and Gin is a practical course in building backend APIs with Go and the Gin framework, using GORM with PostgreSQL, validation, middleware, JWT authentication, testing and Docker. It suits developers with basic Go and system administrators who write services in Go, and you leave able to build a tested RESTful API backed by a database.
Gin is a Go web framework widely used by backend teams to build RESTful APIs because it is fast, simple to write and comes with middleware and binding built in. GORM lets you work with a database without writing every line of SQL yourself. Yet many examples are still written the old way, using AutoMigrate instead of versioned migrations, with no validation, no tests and unsafe token handling, so the resulting API works on the developer's machine but is not ready for production.
This course takes learners who know basic Go through building RESTful APIs with Go 1.27 and Gin. It covers tooling, route design, binding and validation, middleware and CORS, then connects to PostgreSQL 18 with GORM, including the new generics API, relationships, transactions and migrations. Learners structure the project in layers, build sign-up and sign-in, protect the API with JWT and roles, document it with OpenAPI, test it with unit and integration tests and package it with Docker. The course closes with a capstone that builds a complete API. (3 days, 6 hours per day, 18 hours in total, Intermediate level.)
What you’ll gain
Build RESTful APIs with Go 1.27 and Gin following sound API design principles
Accept and validate input with binding and validation, with consistent error formats
Write middleware for logging, CORS and access control
Use GORM with PostgreSQL for CRUD, relationships, transactions and migrations
Structure projects into separate handlers, services and repositories
Build sign-up and sign-in and protect the API with JWT and roles
Write unit tests and integration tests for an API
Package the API as a Docker image with OpenAPI documentation for the team
Who this course is for
Developers with basic Go who want to build RESTful APIs for real projects
Backend developers from other languages who are starting with Go and want the approaches teams actually use
System administrators and DevOps engineers who write services or internal tools in Go
Development teams who want a standard, testable Go project structure
Developers who used older versions of Gin or GORM and want to catch up with current practice
Prerequisites
Basic Go, such as variables, functions, structs and slices
Understanding of HTTP methods, status codes and JSON
Familiarity with relational databases and basic SQL
Basic command-line and Git skills
A laptop that can run Go, Docker Desktop and VS Code, with permission to install software
Curriculum
Course Details
This course is the 2026 edition that replaces the previous RESTful API with Go and Gin course. It has been rewritten for Go 1.27, the current Gin release, GORM and PostgreSQL 18. It runs for 3 days, 6 hours per day (18 hours in total, 09:00-16:00), as lectures with labs built on a single sample store API that grows throughout the course. Intermediate level. It uses the new GORM generics API and versioned migrations, and adds validation, a layered project structure, refresh tokens, OpenAPI documentation, integration tests and Docker. Every lab runs on the learner's own machine with open source tools. Learners take home a lab guide, source code for every lab and docker-compose files.
Day 1Gin and API Fundamentals
Section 1: Lab: Setting Up Tools for Go 1.27
Install Go 1.27 and set up VS Code with the Go extension and gopls
Create a project with go mod init and manage dependencies
Hot reload during development with Air
Test APIs with Postman, Bruno or .http files in VS Code
Lab: run a first web server and call it from a testing tool
Section 2: Go Review for API Work
Structs, methods and JSON tags for exchanging data
Slices, maps and looping with for range
Error handling with errors.Is, errors.As and wrapped errors
Interfaces and generics commonly used in backend code
context for timeouts and request cancellation
Section 3: Lab: Starting a RESTful API with Gin
RESTful API design principles: resources, methods and status codes
gin.Default versus gin.New and choosing your own middleware
Routes, route groups, path parameters and query strings
Return JSON responses and keep error formats consistent
Graceful shutdown with http.Server and context
Section 4: Binding and Validation
ShouldBindJSON, ShouldBindQuery and ShouldBindUri
Validation rules with binding tags such as required, email and min
Write custom validators for business rules
Turn validation errors into messages the frontend can use
Lab: a customer API with a complete set of validation rules
Section 5: Lab: Middleware, CORS and Uploads
How middleware is ordered, and writing your own middleware
Structured logging with log/slog and request IDs
Configure CORS safely with gin-contrib/cors
Upload files with multipart forms, limiting size and file type
Lab: set up a standard middleware stack for the API
Day 2PostgreSQL and GORM
Section 6: Lab: PostgreSQL 18 and the ORM Concept
Run PostgreSQL 18 with Docker Compose and volumes
What an ORM offers and where it falls short compared with hand-written SQL
Connect GORM to PostgreSQL and configure the connection pool
Turn on SQL logging to see the statements GORM actually generates
Section 7: Models, Schemas and Migrations
Define models with structs and GORM tags
Numeric or UUID primary keys, indexes and unique constraints
Soft delete and created and updated timestamps
AutoMigrate for experiments versus versioned migrations with golang-migrate
Lab: design a store schema and create the first migration
Section 8: Lab: CRUD with the GORM Generics API
Meet the new gorm.G generics API available since GORM 1.30
Create, First, Find, Update and Delete with context
Query conditions, pagination and sorting from the query string
Handle missing records with ErrRecordNotFound
Lab: a product CRUD API covering every endpoint
Section 9: Relationships, Joins and Transactions
Has one, has many, belongs to and many to many
Preload versus Joins, and avoiding the N+1 query problem
Transactions for work that must succeed across several tables
When to write raw SQL safely instead of using the ORM
Lab: an order system that reduces stock inside a transaction
Section 10: Lab: A Testable Project Structure
Separate handlers, services and repositories by responsibility
Define repositories as interfaces so they can be swapped and tested
Wire dependencies in main with constructor injection
Manage configuration and secrets through environment variables
Lab: refactor the product and order APIs into the new structure
Day 3Authentication, Testing and Deployment
Section 11: Lab: Sign-Up and Sign-In
Design the users table and prevent duplicate emails
Store passwords with bcrypt and set a password policy
Sign-up and sign-in APIs with validation
Error messages that do not reveal more than necessary
Section 12: Lab: JWT and Authorisation Middleware
The structure of a JWT and bearer tokens
Issue access and refresh tokens with golang-jwt v5
Middleware that verifies tokens and passes user details through gin.Context
Role-based permissions such as Admin and User
Lab: protect the product and order APIs by user permission
Section 13: API Documentation and Security
Generate OpenAPI documentation from code comments with swag and view it in Swagger UI
API versioning and response formats that are easy for the frontend team
Rate limiting and request size limits
Common weaknesses from the OWASP API Security Top 10
Section 14: Lab: Unit Tests and Integration Tests
Table-driven unit tests with the testing package
Test handlers with httptest and gin.TestMode
Mock repositories to test services without a database
Integration tests against a real PostgreSQL with Testcontainers for Go
Measure test coverage and run tests automatically before merging
Section 15: Workshop: Docker and Capstone
Write a multi-stage Dockerfile for a small, secure image
Docker Compose for the API and PostgreSQL with health checks
Capstone: build a booking or inventory API from start to finish
Present the work, review the code together and wrap up with a pre-production checklist
Schedule & training options
For individuals — public rounds
5–7January
Classroom5–7 Jan 27
20 seats left
9–11March
Classroom9–11 Mar 27
20 seats left
11–13May
Classroom11–13 May 27
20 seats left
6–8July
Classroom6–8 Jul 27
20 seats left
1–3September
Classroom1–3 Sep 27
20 seats left
23–25November
Classroom23–25 Nov 27
20 seats left
For organisations — in-house / private
Tailor the content to your team’s tools and projects
What is Gin, and why is it popular for building REST APIs in Go?
Gin is a Go web framework with a fast, memory-efficient router. It supports middleware for work repeated on every request, such as logging, CORS or access checks, binds and validates JSON into structs with ShouldBindJSON and validation rules, and lets you group routes. That makes APIs shorter to write than with net/http alone, while still working with Go's standard http.Server, for example for graceful shutdown.
What are the steps to build a REST API with Gin and PostgreSQL through GORM?
Run go mod init and install Gin, GORM and the PostgreSQL driver. Open a connection with gorm.Open and configure the connection pool, define structs as models and create tables with versioned migrations (AutoMigrate suits experiments). Write repositories with the gorm.G generics API and context, and have handlers read input with c.ShouldBindJSON, validate it and call a service, attached to a route group. Then test with Postman or Bruno and add automated tests.
How do you write JWT-checking middleware in Gin?
Write a function returning gin.HandlerFunc that reads the Authorization header and strips the Bearer prefix. Verify the token's signature, algorithm and expiry with golang-jwt v5. If it is invalid, call c.AbortWithStatusJSON with 401; otherwise store the user details with c.Set and call c.Next. Attach it to the route group that requires login, add role-checking middleware for restricted routes, and use refresh tokens instead of long-lived access tokens.
Who is the RESTful API with Go and Gin course for, and what should I know beforehand?
It suits developers with basic Go who want to build RESTful APIs backed by a database, backend developers from other languages who are starting with Go, and system administrators or DevOps engineers who write services in Go. You should be able to write basic Go, understand HTTP and JSON, and know basic SQL.
What will I be able to do after the RESTful API with Go and Gin course?
You will be able to build RESTful APIs with Gin using binding, validation and middleware, configure CORS and file uploads, run CRUD, relationships and transactions in PostgreSQL through GORM with migrations, structure a testable project, build sign-up and login with bcrypt, JWT and roles, write OpenAPI documentation, write unit and integration tests and build Docker images. Participants who complete the training receive a Certificate of Completion with its own number, which can be verified online.
What software do I need for RESTful API with Go and Gin?
You use Go 1.27 and VS Code with the Go extension, Air for hot reload so the project restarts automatically when code changes, Postman or Bruno to test APIs, and PostgreSQL 18 running in Docker Desktop. All the tools are free and are installed together during the training, so bring a laptop on which you can install software.
Many PHP websites start as procedural code that is quick to write and easy to follow. As the system grows, functions end up scattered across every file, SQL is mixed with HTML, and a change in one place breaks several others until nobody dares to touch it.…
Most PHP work in organisations does not start from scratch. Teams extend existing systems, connect to several kinds of database and expose APIs for other systems to call. Object-oriented code splits a system into parts with clear responsibilities, and…
Many people who can already write Java still put everything into a few large classes. As the system grows it becomes hard to change, hard to test and impossible to reuse. Thinking in objects properly gives each piece of code a clear responsibility, and modern…