Coder Social home page Coder Social logo

danielliu1123 / httpexchange-spring-boot-starter Goto Github PK

View Code? Open in Web Editor NEW
19.0 3.0 1.0 1.73 MB

The missing starter for Spring 6.x declarative HTTP client. Eliminate boilerplate code, server base implementation code generation, RequestMapping annotation support, loadbalancer support, native-image support, dynamic refreshing, dynamic request timeout, and more!

Home Page: https://danielliu1123.github.io/httpexchange-spring-boot-starter/

License: MIT License

Java 82.26% Shell 0.02% JavaScript 0.03% MDX 14.43% TypeScript 2.25% CSS 1.00%
http-client spring-boot spring-boot-starter spring6 declarative-http-client jdk17 spring-cloud reactive graalvm native-image

httpexchange-spring-boot-starter's Introduction

Hi there ๐Ÿ‘‹

Here is Freeman's homepage.

Programming and art enthusiast.

๐ŸŒฑ Keep studying.

๐Ÿƒ Keep programming.

๐ŸŒŸ Keep thinking.

๐ŸŽ Keep creating.

๐Ÿ’š WORLD PEACE ๐Ÿ’š

httpexchange-spring-boot-starter's People

Contributors

danielliu1123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

sjh836

httpexchange-spring-boot-starter's Issues

Adding configuration suuport

http-exchange:
  default-base-url: http://api-gateway
  default-response-timeout: 10000
  default-headers:
    X-Header1: v1
    X-Header2: [v1, v2]
  clients:
    - name: OrderApi
      base-url: http://order
      response-timeout: 1000
    - name: UserApi
      base-url: http://user
      response-timeout: 2000

Support Spring web (server side) annotation

Support Spring web server side annotation, like Spring Cloud Openfeign.

e.g. @GetMapping, @PostMapping.

@RequestMapping("/foo")
class FooApi {
    @GetMapping("/{id}")
    Foo getFooById(@PathVariable String id);
}

Configured so that each channel can use different clients

This library is really well made.
It is a spring feature that can be easily applied right away.

I have to use both the normal return type and the return type of Reactive Stream through the http interface.
Also, I would like to adjust the timeout dynamically.

Therefore, I hope it works as follows.
I wish each channel could have a separate remote client.

http-exchange:
  enabled: true
  refresh:
    enabled: false
  read-timeout: 2000
  connect-timeout: 500
  #client-type: WEB_CLIENT
  channels:
    - base-url: 'https://jsonplaceholder.typicode.com'
      #client-type: REST_CLIENT #here
      #read-timeout: 500
      #connect-timeout: 200
      clients:
        - com.devljh.module.http.*HttpClient
    - base-url: 'https://jsonplaceholder.typicode.com'
      #client-type: WEB_CLIENT #here
      clients:
        - com.devljh.module.http.*ReactiveHttpClient

It doesn't work now, and an error occurs because the rest client cannot convert Mono/Flux messages.

httpexchange-processor generate interface default implementation

Api:

@Validated
@HttpExchange("/user")
public interface UserApi {
    @GetExchange("/{id}")
    UserDTO getUser(@PathVariable("id") @NotBlank @Length(max = 5) String id);
}

Generate default implementation for server:

// Generate interface
@Validated
@HttpExchange("/user")
public interface UserApiBase {
    @GetMapping("/{id}")
    default UserDTO getUser(@PathVariable("id") @NotBlank @Length(max = 5) String id) {
        throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED);
    }
}

do not create a new HttpClient when it is not necessary

In the buildRestClient method, HttpClient settings other than timeout are unintentionally initialized.

  • I set RetryStrategy, evictIdleConnections, ObservationExecChainHandler etc in HttpClient.
  • Read timeout was not set in yaml.
  • This is because ClientHttpRequestFactories.get always creates a new HttpClient.

(not a bug) Quesion about your wiki

Love what you did with this.

I am curious about how you generated your Wiki. I'm assuming from your README.md file some frontend library you used?

Thank you!

use APT to generate base implementation for server

Api:

@Validated
@HttpExchange("/user")
public interface UserApi {
    @GetExchange("/{id}")
    UserDTO getUser(@PathVariable("id") @NotBlank @Length(max = 5) String id);
}

Generate base implementation for server:

// generate interface?
public interface UserApiBase extends UserApi {
    @Override
    default UserDTO getUser(String id) {
        throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED);
    }
}

// or generate abstract class? Just like gRPC
public abstract class UserApiBase implements UserApi {
    @Override
    public UserDTO getUser(String id) {
        throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED);
    }
}

Maybe generate abstract class is a better chioce? Generation interface may lead to unexpected behavior(@Validated not work as expected).

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.