Web服务REST API版本控制是否有任何已知的方法或最佳实践?
我注意到AWS通过端点的URL进行版本控制.这是唯一的方法还是有其他方法来实现同一目标?如果有多种方式,每种方式的优点是什么?
我正在使用Spring Data JPA和Spring Data REST开发基于组件的CRUD应用程序.我有几个组件.例如,系统组件具有User模型和UserRepository.组件由包名称区分.喜欢com.example.app.<component_name>
因此,为了使我的REST API看起来更干净,我需要实现API URL,如下所示.
host:8080/<component_name>/<model_collection_name>
例如
host:8080/system/users
我在我的存储库中执行了以下操作
@RepositoryRestResource(collectionResourceRel = "users", path = "system/users")
public interface UserRepository extends PagingAndSortingRepository<User, Long> {
...
}
Run Code Online (Sandbox Code Playgroud)
当我转到时,这会生成以下内容 http://localhost:8080
{
"_links": {
"users": {
"href": "http://localhost:8080/system/users{?page,size,sort}",
"templated": true
},
...
Run Code Online (Sandbox Code Playgroud)
但是当我转到 http://localhost:8080/system/users
它给出了一个错误
5月22日星期五17:56:37 IST 2015出现意外错误(type = Not Found,status = 404).没有可用的消息
注意:如果我将路径映射到system-users那么它工作正常,但是当我/在路径中使用a 时system/users,它会中断并给出错误.
想知道@VersionSpring Data REST中的注释如何用于ETag,我没有看到由于某种原因填充了ETag
@Entity
@EntityListeners(AuditingEntityListener.class)
public class Venue implements Serializable {
private static final long serialVersionUID = -5516160437873476233L;
private Long id;
...
// other properties
private Long version;
private Date lastModifiedDate;
// getters & setters
@JsonIgnore
@LastModifiedDate
public Date getLastModifiedDate() {
return lastModifiedDate;
}
@Version
@Column
public Long getVersion() {
return version;
}
Run Code Online (Sandbox Code Playgroud)
通过文档,这应该给我一个Etag价值?如图书馆的片段所示
protected HttpHeaders prepareHeaders(PersistentEntity<?, ?> entity, Object value) {
// Add ETag
HttpHeaders headers = ETag.from(entity, value).addTo(new HttpHeaders());
// Add Last-Modified
AuditableBeanWrapper wrapper = getAuditableBeanWrapper(value); …Run Code Online (Sandbox Code Playgroud)