Skip to content

knightliao/JRestClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JRestClient

=======

Apache License 2 Build Status Coverage Status Maven Central Maven Central

rest http client

Func

  • restclient
    • rest http client
  • restclient-spring
    • rest http client using spring

Quick Start

interface:

public interface KvRestClient {

    @RequestType(type = RequestTypeEnum.GET)
    Map<String, String> getDbKv(@RequestParam(name = "tableId") String tableId,
                                @RequestParam(name = "key") String key);

    @RequestType(type = RequestTypeEnum.GET)
    User getUser(@RequestParam(name = "tableId") String tableId,
                 @RequestParam(name = "key") String key);
}

test example:

@Test
public void testWithKv() {

    try {

        KvRestClient restClient =
                (KvRestClient) RestClient.create().servers("127.0.0.1:8398,127.0.0.1:8398").
                        serviceUrl("/canalx/rest/get")
                        .serviceInterface(KvRestClient.class).build();

        Map<String, String> ret = restClient.getDbKv("test.user", "1");

        Assert.assertEquals(ret.get("id"), 2);
        Assert.assertEquals(ret.get("name"), "ffdd");
        Assert.assertEquals(ret.get("phone"), "");

    } catch (Exception e) {

        Assert.assertTrue(false);
    }
}

@Test
public void testWithObject() {

    try {

        KvRestClient restClient =
                (KvRestClient) RestClient.create().servers("127.0.0.1:8398,127.0.0.1:8398").serviceUrl("/canalx/rest/get")
                        .serviceInterface(KvRestClient.class).build();

        User user = restClient.getUser("test.user", "1");

        Assert.assertEquals(user.getId(), 2);
        Assert.assertEquals(user.getName(), "ffdd");
        Assert.assertEquals(user.getPhone(), "");

    } catch (Exception e) {

        Assert.assertTrue(false);
    }
}

doc: http://restclient.readthedocs.io/en/latest/

Maven

jutf

<dependency>
    <groupId>com.github.knightliao.canalx.rest</groupId>
    <artifactId>restclient</artifactId>
    <version>0.0.1</version>
</dependency>

jutf-Spring

<dependency>
    <groupId>com.github.knightliao.canalx.rest</groupId>
    <artifactId>restclient-spring</artifactId>
    <version>0.0.1</version>
</dependency>

About

一个Java HTTP 客户端。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages