Skip to content

API Specification

The .api file format defines HTTP services using a simple, readable DSL inspired by go-zero.

Overview

API specification files describe:

  • Types - Request and response structures
  • Services - HTTP routes and handlers
  • Middleware - Request processing pipeline
  • Groups - Logical grouping of routes

Quick Example

api
syntax = "v1"

type (
    CreateTodoReq {
        Title       string `json:"title"`
        Description string `json:"description,optional"`
    }
    
    Todo {
        Id          int64  `json:"id"`
        Title       string `json:"title"`
        Description string `json:"description"`
        Done        bool   `json:"done"`
    }
)

@server (
    prefix: /api/v1
    group: todo
)
service todo-api {
    @handler CreateTodo
    post /todos (CreateTodoReq) returns (Todo)
    
    @handler GetTodo
    get /todos/:id returns (Todo)
    
    @handler ListTodos
    get /todos returns ([]Todo)
}

Documentation

  • Syntax - File structure and basic syntax
  • Types - Type definitions and field tags
  • Services - Route definitions and middleware

Generated Code

When you run ss api gen, the following is generated:

ComponentLocationDescription
Typesinternal/types/types.goRequest/response structs
Handlersinternal/handler/HTTP handlers
Logicinternal/logic/Business logic layer
Routesinternal/handler/routes.goRoute registration
Configinternal/config/config.goConfiguration struct
Entrycmd/main.goServer entry point

Released under the MIT License.