簡體   English   中英

使用CRest的可配置端點

[英]Configurable Endpoints using CRest

我正在嘗試創建一個使用CRest與RESTful Web服務接口的Android應用程序。

我遇到的問題與服務的創建有關。 在Twitter示例中,EndPoint設置為靜態URL(api.twitter.com),但在我的情況下,我需要將其配置為可配置的,因為直到用戶指定端點,我們才知道端點。

我想做的事情與此類似:

@EndPoint("http://%s.somedomain.com")
@ContextPath("/admin")

public interface ProductService {
    @Path("/products.json")
    InputStream getProducts();

    @Path("/products/{0}.json")
    InputStream getProduct(int id);
}

有沒有一種方法可以在創建服務時指定EndPoint

順便說一句,占位符實現在那里並且現在有文檔http://crest.codegist.org/annotations/api.html

@EndPoint("http://{my.interface.host}")
public interface MyInterface {
    ...
}

用於

String myInterfaceHost = ...;

CRest crest = CRest.placeholder("my.interface.host", myInterfaceHost).build();

MyInterface myInterface = crest.build(MyInterface.class);

看一下快速入門鏈接,在底部可以找到以下代碼:

Properties props = new Properties();
props.setProperty("service.end-point", "http://127.0.0.1:8080");

CRest crest = new CRestBuilder()
                        .overrideDefaultConfigWith(props)
                        .build();

如您所提到的,通過Builder或通過在注釋值上帶有占位符的約定,下一發行版將具有更簡便的方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM