Skip to main content
The API template creates a well-structured JSON API service. An API (Application Programming Interface) is a way for programs to talk to each other - when you build an API, you create endpoints (URLs) that other programs can call to get or send data, usually in JSON format. This template is designed for production use with a clean architecture that scales as your project grows.

When to Use This Template

Use the API template when:
  • Building a REST API - JSON endpoints for web or mobile clients
  • Multiple developers - Clear structure everyone can follow
  • Production service - Ready for deployment
  • Need organization - More than a few routes

What You Get

A complete project structure with:
  • Feature-based organization - Code grouped by domain
  • Configuration management - Environment-based config
  • App lifecycle - Clean startup and shutdown
  • Example endpoints - Health check, echo, users

Quick Start

Test it:

Project Structure

Key Features

Feature-Based Organization

Each feature (domain/module) gets its own folder:
This keeps related code together and makes it easy to find things.

Configuration Management

Configuration is loaded from environment variables:

Application Structure

The App struct manages lifecycle:

Example Routes

Health Check

Hello Endpoint

Users API

Echo Endpoint

Why This Structure?

Scalability

As your API grows, add new features without cluttering existing code:

Testability

Each feature can be tested independently:

Team Collaboration

Clear boundaries mean less merge conflicts:
  • Developer A works on feature/users/
  • Developer B works on feature/products/

Maintainability

Find code easily:
  • β€œWhere’s the user creation logic?” β†’ feature/users/
  • β€œWhere are routes defined?” β†’ app/api/routes.go
  • β€œWhere’s the config?” β†’ app/api/config.go

Comparison with Minimal

Next Steps

Project Structure

Detailed file-by-file explanation

Tutorial

Build a complete API step by step