An open API service indexing awesome lists of open source software.

https://github.com/ashutoshsahoo/gs-spring-boot-http-client

Spring Declarative HTTP Client using @HttpExchange
https://github.com/ashutoshsahoo/gs-spring-boot-http-client

getexchange httpexchange postexchange spring-boot3 spring-boot3x spring6

Last synced: 2 months ago
JSON representation

Spring Declarative HTTP Client using @HttpExchange

Awesome Lists containing this project

README

          

# gs-spring-boot-http-client

Spring Declarative HTTP Client using @HttpExchange

* Declaration

```java

@HttpExchange(url = "/users",
accept = MediaType.APPLICATION_JSON_VALUE,
contentType = MediaType.APPLICATION_JSON_VALUE)
public interface UserClient {

@GetExchange
List getAll();

@GetExchange("/{id}")
UserDto getById(@PathVariable("id") Long id);

@PostExchange
ResponseEntity save(@RequestBody UserDto userDto);

@PutExchange("/{id}")
ResponseEntity update(@PathVariable Long id, @RequestBody UserDto userDto);

@DeleteExchange("/{id}")
ResponseEntity delete(@PathVariable Long id);

}

```

* Configuration

```java

@Configuration
public class UserClientConfig {

@Bean
RestClient restClient() {
return RestClient.builder()
.baseUrl("https://jsonplaceholder.typicode.com/")
.build();
}

@Bean
UserClient userClient(RestClient restClient) {
HttpServiceProxyFactory httpServiceProxyFactory =
HttpServiceProxyFactory.builderFor(RestClientAdapter.create(restClient))
.build();
return httpServiceProxyFactory.createClient(UserClient.class);
}
}

```