Git Product home page Git Product logo

httpexchange-spring-boot-starter's Introduction

httpexchange-spring-boot-starter

Build JDK Version Maven Central License: Apache-2.0

@FeignClient@RetrofitClient 那样使用 Spring Boot 3.x 中的 HTTP Interface

快速开始

引入依赖

<dependency>
    <groupId>io.github.llnancy</groupId>
    <artifactId>httpexchange-spring-boot-starter</artifactId>
    <version>0.0.2</version>
</dependency>

定义 HTTP 接口

接口必须使用 @io.github.llnancy.httpexchange.core.ExchangeClient 注解标记HTTP 相关注解可参考官方文档:Spring 官方文档

@ExchangeClient(baseUrl = "${test.baseUrl}")
public interface HttpApi {

    @PostExchange("/post")
    Mono<Map<String, Object>> post(@RequestBody Map<String, Object> params);
}

注入使用

将接口注入到其它 Service 中即可使用!

@Service
public class TestService {

    @Autowired
    private HttpApi httpApi;

    public void test() {
       // 使用 httpApi 发起 HTTP 请求
    }
}

Q & A

报错 Caused by: org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144

Caused by: org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144
	at org.springframework.core.io.buffer.LimitedDataBufferList.raiseLimitException(LimitedDataBufferList.java:99)

具体参考 https://www.baeldung.com/spring-webflux-databufferlimitexception

本框架支持的方式如下:

  1. 自定义一个 io.github.llnancy.httpexchange.core.ClientCodecConfigurerConsumer

        @Component
        class MyClientCodecConfigurerConsumer implements ClientCodecConfigurerConsumer {
    
            @Override
            public Consumer<ClientCodecConfigurer> consumer() {
                return configurer -> configurer.defaultCodecs()
                        .maxInMemorySize(500 * 1024);
            }
        }
  2. @ExchangeClient 注解中指定 codecConfigurerConsumer

    @ExchangeClient(baseUrl = "https://lilu.org.cn", codecConfigurerConsumer = MyClientCodecConfigurerConsumer.class)
    public interface MyExchangeClient {
    }

支持编译为 native 镜像吗?

支持。

License

Apache License 2.0

Copyright (c) 2023-present llnancy

httpexchange-spring-boot-starter's People

Contributors

llnancy avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.