spring rest client

convenient spring rest client for rest services

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

com.github.bingoohuang
ArtifactId

ArtifactId

spring-rest-client
Last Version

Last Version

0.0.23
Release Date

Release Date

Type

Type

jar
Description

Description

spring rest client
convenient spring rest client for rest services
Project URL

Project URL

http://github.com/bingoohuang/spring-rest-client
Source Code Management

Source Code Management

http://github.com/bingoohuang/spring-rest-client

Download spring-rest-client

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.bingoohuang/spring-rest-client/ -->
<dependency>
    <groupId>com.github.bingoohuang</groupId>
    <artifactId>spring-rest-client</artifactId>
    <version>0.0.23</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.bingoohuang/spring-rest-client/
implementation 'com.github.bingoohuang:spring-rest-client:0.0.23'
// https://jarcasting.com/artifacts/com.github.bingoohuang/spring-rest-client/
implementation ("com.github.bingoohuang:spring-rest-client:0.0.23")
'com.github.bingoohuang:spring-rest-client:jar:0.0.23'
<dependency org="com.github.bingoohuang" name="spring-rest-client" rev="0.0.23">
  <artifact name="spring-rest-client" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.bingoohuang', module='spring-rest-client', version='0.0.23')
)
libraryDependencies += "com.github.bingoohuang" % "spring-rest-client" % "0.0.23"
[com.github.bingoohuang/spring-rest-client "0.0.23"]

Dependencies

compile (11)

Group / Artifact Type Version
com.github.bingoohuang : blackcat-instrument Optional jar 0.0.13
org.apache.httpcomponents : httpasyncclient jar 4.1
org.slf4j : slf4j-api jar 1.7.12
org.springframework : spring-webmvc jar 5.0.7.RELEASE
com.github.bingoohuang : diamond-client Optional jar 0.0.18
org.ow2.asm : asm jar 5.0.3
com.github.bingoohuang : java-utils jar 0.0.11
com.github.bingoohuang : unirest-java jar 0.0.7
com.google.guava : guava jar 25.1-jre
com.alibaba : fastjson jar 1.2.47
com.github.bingoohuang : asmvalidator jar 0.0.15

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok Optional jar 1.18.0

test (11)

Group / Artifact Type Version
com.github.bingoohuang : spring-rest-boot jar 0.0.12
com.github.bingoohuang : westcache jar 0.0.32
com.github.bingoohuang : voucher-no jar 0.0.6
org.jmockit : jmockit jar 1.40
commons-fileupload : commons-fileupload jar 1.3
org.springframework.boot : spring-boot-starter-web jar 2.0.3.RELEASE
org.springframework.boot : spring-boot-starter-security jar 2.0.3.RELEASE
org.springframework.boot : spring-boot-starter-test jar 2.0.3.RELEASE
ch.qos.logback : logback-classic jar 1.1.3
com.google.truth : truth jar 0.41
com.github.bingoohuang : westid jar 0.0.2

Project Modules

There are no modules declared in this project.

spring-rest-client

spring rest client

a rest api can be written using spring mvc like this:

@RestController
@RequestMapping("/another")
public class AnotherController {
    @RequestMapping("/add")
    public int add(@RequestParam("offset") int offset) {
        // do something
        return offset ;
    }
}

a rest client can be declared like this:

@RequestMapping("/another")
@SpringRestClientEnabled(baseUrl = "http://localhost:8080")
public interface AnotherApi {
    @RequestMapping("/add")
    int add(@RequestParam("offset") int offset);
}

And then import spring-rest-client config like this:

@Configuration
@ComponentScan
@SpringRestClientEnabledScan
public class SpringRestClientConfig {
}

And then you can call the api like this:

@Autowired AnotherApi anotherApi;

int a = 123;
int account = anotherApi.add(a);

Bypass spring boot request mapping

// for spring boot 2.0
import com.github.bingoohuang.springrestclient.annotations.SpringRestClientEnabled;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

import java.lang.reflect.Method;

@Configuration
public class SpringFrontConfig {
    @Bean
    public WebMvcRegistrations webMvcRegistrationsAdapter() {
        return new WebMvcRegistrations() {
            @Override
            public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
                return new RequestMappingHandlerMapping() {
                    @Override protected void registerHandlerMethod(Object handler, Method method, RequestMappingInfo mapping) {
                        // by pass SpringRestClientEnabled interface
                        if (method.getDeclaringClass().isAnnotationPresent(SpringRestClientEnabled.class)) return;
                        super.registerHandlerMethod(handler, method, mapping);
                    }
                };
            }
        };
    }

}
// for spring boot 1.x

import com.github.bingoohuang.springrestclient.annotations.SpringRestClientEnabled;
import org.springframework.boot.autoconfigure.web.WebMvcRegistrationsAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

import java.lang.reflect.Method;

@Configuration
public class SpringConfig {
    @Bean
    public WebMvcRegistrationsAdapter webMvcRegistrationsAdapter() {
        return new WebMvcRegistrationsAdapter() {
            @Override
            public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
                return new RequestMappingHandlerMapping() {
                    @Override
                    protected void registerHandlerMethod(Object handler, Method method, RequestMappingInfo mapping) {
                        // by pass SpringRestClientEnabled interface
                        if (method.getDeclaringClass().isAnnotationPresent(SpringRestClientEnabled.class)) return;
                        super.registerHandlerMethod(handler, method, mapping);
                    }
                };
            }
        };
    }
}

Versions

Version
0.0.23
0.0.22
0.0.21
0.0.20
0.0.19
0.0.17
0.0.16
0.0.15
0.0.14
0.0.13
0.0.12
0.0.11
0.0.10
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2