Skip to content

Migrate to the 0.7.5 API ​

Review the HTTP inputs, context, and application assembly changes when upgrading to Spine v0.7.5.

Upgrade to the stable release ​

Run these commands in an existing app that uses Echo. For other HTTP implementations, check the compatible versions in the platform guide. If your app uses HTTP v2, upgrade to its HTTP v3 platform as well.

sh
go install github.com/NARUBROWN/spine-cli/cmd/spine@v0.4.4
spine version
go get github.com/NARUBROWN/spine@v0.7.5 github.com/NARUBROWN/spine-echo-platform@v0.2.1

Controllers and DTOs ​

go
type UserPath struct {
	ID int64 `path:"id"`
}
type UserQuery struct {
	Name string `query:"name"`
}
type UserHeaders struct {
	RequestID string `header:"X-Request-ID"`
}
type CreateUser struct {
	Name string `json:"name" validate:"required"`
}

func (*UserController) RegisterRoutes(r *api.Registry) {
	users := r.Group("/users", api.Interceptors((*Auth)(nil)))
	users.GET("/:id", func(path input.Path[UserPath]) httpx.Response[map[string]int64] {
		return httpx.Response[map[string]int64]{Body: map[string]int64{"id": path.ID}}
	})
	users.POST("/", func(body input.Body[CreateUser]) httpx.Response[CreateUser] {
		return httpx.Response[CreateUser]{Body: *body, Options: httpx.ResponseOptions{Status: 201}}
	})
}

Use input.Path[UserPath], input.Query[UserQuery] and input.Header[UserHeaders] consistently. Bare *DTO HTTP inputs are rejected. Path/Query/Header default to lowerCamel names, overridden by tags. Body follows json/xml/form decoder rules. Only one success response is allowed; multiple responses and invalid or conflicting XML field tags fail preparation.

Controller and DTO details

Assembly and automatic validation ​

go
engine, err := playground.New()
if err != nil {
	return nil, boot.Options{}, err
}
app := spine.New(echoplatform.Option(), spine.WithValidator(engine))
app.Constructor(
	constructor.Repository(&UserRepository{}),
	constructor.Service(&UserService{}),
	constructor.Controller(&UserController{}),
	constructor.Interceptor(&Auth{}),
)

Place this fragment in BuildApplication with the required types and imports. engine is the playground.New instance. Automatic tag validation needs no DTO Validate method. Implement additional methods yourself and call (*body).Validate() where needed; OpenAPI does not infer their bodies. app.Validate checks app configuration. Constructors support one return value and reject variadic parameters.

DI / Validation modes

Context and interceptors ​

HTTP handlers can declare pkg/spine.Ctx when they need the request context. All interceptor hooks receive pkg/spine.Ctx. Direct standard context.Context injection remains compatible. Use ExecutionContext().Context() for DB/events, Set/Get for execution values, and public transport views for HTTP/WebSocket. Global and route PreHandle run before binding. BeforeResponse errors take response priority; HTTPError accepts only 400–599. AfterCompletion follows the write attempt and is not a commit point.

Context / Scopes / Transactions

CLI and compatibility code ​

CLI v0.4.4 generates RegisterRoutes, role constructors, and HTTP input wrappers. After migrating, run go mod tidy, spine contract check, and spine verify, then verify actual HTTP requests. app.Route, route.WithInterceptors, query.Values, header.Values, path and multipart.UploadedFiles are deprecated compatibility APIs, not for new examples or generated code. Older migration pages describe their historical behavior; use this page for the current API.

Project structure / Versions

Upgrading from 0.7.1 ​

Upgrade to v0.7.5 if your app uses the retracted Go module version v0.7.1. Wrap DTO pointers in existing HTTP handlers according to their input source and update your HTTP platform to a compatible version.