问题是关于REST API的最佳实践。
示例:我有一个带有path-param的get API作为状态。
/api/{status}
现在,在代码中,状态被定义为枚举(状态)。只有3个(或一些小的有限)可能的状态值。
public enum Status {
created,
completed,
cancelled
}
所以,我应该接受" status"作为字符串或枚举类型?
@Path("/api/{status}")
@GET
public Response get(@PathParam("status") String status) {}
// then I can check if it is a valid status
OR
@Path("/api/{status}")
@GET
public Response get(@PathParam("status") Status status) {}
// it will throw an exception if it is an invalid status
另外,我想了解有关query-params和JSON请求的最佳实践。