我对API构建相当陌生,所以这可能是一个比我最初提出的更广泛的问题。我正在戈朗中创建一个API(使用原型buf 3和gRPC),它有两个类似的端点:
获取 /项目/流派
获取 /项目/{id}
问题是,当我运行 时,模式匹配会导致端点被调用作为id。有没有一些简单的方法可以解决这个问题,或者我必须在服务器代码中构建一些东西来根据类型调用正确的函数?curl localhost:8080/project/genres/project/{id}genres
我还尝试翻转这些定义的顺序,以防万一模式匹配有一些我不知道的操作顺序,但这并没有区别。
以下是我的原型文件中的定义:
message EmptyRequest { }
message ProjectRequest {
string id = 1;
}
message GenreResponse {
int32 id = 1;
string name = 2;
}
message ProjectResponse {
int32 id = 1;
string name = 2;
}
service ProjectService {
rpc GetProject(ProjectRequest) returns (ProjectResponse) {
option (google.api.http) = {
get: "/v1/project/{id}"
};
}
rpc GetGenres(EmptyRequest) returns (GenreResponse) {
option (google.api.http) = {
get: "/v1/project/genres"
};
}
}
小唯快跑啊
相关分类