Cloud 的 endpoints .
我正在关注Udacity tutorial.i与请求和响应的流程有点混淆,下面是我的理解
endpoints 应使用_2527359注释, endpoints 方法使用 @ApiMethod
注释,并且这些方法不应返回原始数据类型 . 以下是一个 endpoints 方法
@ApiMethod(name = "saveProfile", path = "profile", httpMethod = HttpMethod.POST)
public Profile saveProfile(ProfileForm profileForm) throws UnauthorizedException {
String userId = null;
String mainEmail = null;
String displayName = "Your name will go here";
TeeShirtSize teeShirtSize = TeeShirtSize.NOT_SPECIFIED;
if(profileForm.getTeeShirtSize() != null)
teeShirtSize = profileForm.getTeeShirtSize();
displayName = profileForm.getDisplayName();
Profile profile = new Profile(userId, displayName, mainEmail, teeShirtSize);
return profile;
}
以下是我的ProfileForm和Profile类
public class ProfileForm {
private String displayName;
private TeeShirtSize teeShirtSize;
private ProfileForm () {}
public ProfileForm(String displayName, TeeShirtSize teeShirtSize) {
this.displayName = displayName;
this.teeShirtSize = teeShirtSize;
}
public String getDisplayName() {
return displayName;
}
public TeeShirtSize getTeeShirtSize() {
return teeShirtSize;
}
public static enum TeeShirtSize {
NOT_SPECIFIED,
XS,
S,
M,
L,
XL,
XXL,
XXXL
}
}
public class Profile {
String displayName;
String mainEmail;
TeeShirtSize teeShirtSize;
String userId;
public Profile (String userId, String displayName, String mainEmail, TeeShirtSize teeShirtSize) {
this.userId = userId;
this.displayName = displayName;
this.mainEmail = mainEmail;
this.teeShirtSize = teeShirtSize;
}
public String getDisplayName() {
return displayName;
}
public String getMainEmail() {
return mainEmail;
}
public TeeShirtSize getTeeShirtSize() {
return teeShirtSize;
}
public String getUserId() {
return userId;
}
private Profile() {}
}
这里 ProfileForm
是请求参数,而 Profile
是在locahost部署的response.i,并使用下面的url我测试过
http://localhost:8080/_ah/api/explorer在请求体中我添加了两个参数作为displayName,teeShirtSize所以任何人都可以解释为什么我得到的响应为404?以下是截图
根据我的理解,我不需要加载appengine client.js,因为我没有在网页上测试 . 我在api-explorer中测试 . 请解释当你调用google-cloud-endpoint时如何生成响应?
谢谢
2 回答
我使用了1.9.3版本的google-app-engine,然后我改为1.9.20现在它's working fine. Still i am hiving questions like why it'在1.9.3中没有用?
谢谢
它's likely (but not certain, because I don' t看到你的
@Api
注释)它没有用,因为你在注释中设置了root参数 . 最近的变化使得API资源管理器始终尊重根本,这打破了本地开发经验 . 最近的SDK版本对此进行了更改以使其再次运行 . 如果您注意到,您的资源管理器截图显示:应该说的地方: