java – 使用Google Cloud Endpoints发送HTTP 201响应

我想在创建资源及其位置后发送201 HTTP响应.

HTTP/1.1 201 Created
Location: http://www.example.org/myresource/12546

你如何定义你的@ApiMethod?

最佳答案 如
the Documentation所述:

HTTP 200 is typically assumed by Endpoints if the API method returns
successfully. If the API method response type is void or the return
value of the API method is null , HTTP 204 will be set instead. HTTP
2xx codes should not be used in custom exception classes.

如果你仍然需要返回201代码,你可以破解服务异常来提供它.

public class EverythingOKException extends ServiceException {
    public EverythingOKException(String message) {
        super(201, message);
    }
}
点赞