Skip to main content

Best Practices

This section shows some best practices for using @HttpExchange.

Contract-Driven Development

@HttpExchange also provides server endpoints, just like @RequestMapping. This makes it ideal for defining interface contracts and supporting contract-driven development.

Project structure:

.
├── order-service
│ ├── order-api
│ └── order-server
└── user-service
├── user-api
└── user-server
@HttpExchange("/orders")
public interface OrderApi {
@GetExchange("/by_user/{userId}")
List<OrderDTO> getOrdersByUserId(@PathVariable("userId") String userId);
}