hz annotation

Supported api annotations

Field annotation can be used forparameter binding and validation

Method annotation can be used to generate code that related to route registration

Supported api annotations

Field annotation
annotationdescription
api.raw_bodygenerate “raw_body” tag
api.querygenerate “query” tag
api.headergenerate “header” tag
api.cookiegenerate “cookie” tag
api.bodygenerate “json” tag
api.pathgenerate “path” tag
api.formgenerate “form” tag
api.go_tag (protobuf)
go.tag (thrift)
passing go_tag through will generate the content defined in go_tag
api.vdgenerate “vd” tag
Method annotation
annotationdescription
api.getdefine GET methods and routes
api.postdefine POST methods and routes
api.putdefine PUT methods and routes
api.deletedefine DELETE methods and routes
api.patchdefine PATCH methods and routes
api.optionsdefine OPTIONS methods and routes
api.headdefine HEAD methods and routes
api.anydefine ANY methods and routes

Usage:

Field annotation:

Thrift:

struct Demo {
    1: string Demo (api.query="demo", api.path="demo");
    2: string GoTag (go.tag="goTag:"tag"");
    3: string Vd (api.vd="$!='your string'");
}

Protobuf:

message Demo {
  string Demo = 1[(api.query)="demo",(api.path)="demo"];
  string GoTag = 2[(api.go_tag)="goTag:"tag""];
  string Vd = 3[(api.vd)="$!='your string'"];
}

Method annotation:

Thrift:

service Demo {
    Resp Method(1: Req request) (api.get="/route");
}

Protobuf:

service Demo {
  rpc Method(Req) returns(Resp) {
    option (api.get) = "/route";
  }
}