繁体   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