2017-02-21 80 views
0

我正尝试使用Restheart API删除集合。如何获得Etag for Restheart集合

$http DELETE 127.0.0.1:8080/testDB/testCollection

,但我得到的错误:

"The collection's ETag must be provided using the 'If-Match' header."

如果我使用GET:

http GET 127.0.0.1:8080/testDB/testCollection

我可以看到从过去的GET请求响应的eTag,为了删除集合手动添加到IF-Match头。

但我不明白我将如何检索给定集合(即testCollection)的_etag。

我的最终目标是使用apache http commons作为REST API客户端从java应用程序中删除集合。因此,Java中的示例非常受欢迎。

回答

1

得到ETAG只是GET 127.0.0.1:8080/testDB/testCollection?pagesize=0,你就其属性中的eTag响应头

http -a a:a 127.0.0.1:8080/db/coll?pagesize=0 
HTTP/1.1 200 OK 
... 
ETag: 58653f6b2d174c09c590262a** 

{ 
    "_embedded": [], 
    "_etag": { 
     "$oid": "58653f6b2d174c09c590262a" 
    }, 
    "_id": "coll", 
    "_returned": 0, 
} 

也注意到,试图删除集合返回的eTag响应头之间找到它冲突案例

http -a a:a DELETE 127.0.0.1:8080/db/coll 
HTTP/1.1 409 Conflict 
... 
ETag: 58653f6b2d174c09c590262a 

{ 
    "http status code": 409, 
    "http status description": "Conflict", 
    "message": "The collection's ETag must be provided using the 'If-Match' header." 
} 

终于可以在配置文件中设置Etag检查行为。

#### ETag policy 

# the following configuration defines the default etag check policy 
# the policy applies for dbs, collections (also applies to file buckets) and documents 
# valid values are REQUIRED, REQUIRED_FOR_DELETE, OPTIONAL 

etag-check-policy: 
    db: REQUIRED_FOR_DELETE 
    coll: REQUIRED_FOR_DELETE 
    doc: OPTIONAL 
:默认是检查的eTag只删除/ db和/科尔,但可以使任何写请求从conf文件(例如,以避免所谓的鬼写的问题)