2 ms·
and what kind of library / ide plugin is used to call rest api in a type safe manner without writing boilerplate ?
by agumonkey 2y ago
and what kind of library / ide plugin is used to call rest api in a type safe manner without writing boilerplate ?
- mike_hearn 2y agoMost frameworks will do that? In Micronaut it's something like this on the client: @Validated public interface PetOperations { @Post @SingleResult Publisher<Pet> save(@NotBlank String name, @Min(1L) int age); } then you inject @Client("https://example.com/pets") @Inject PetOperations pets; and call its methods. It will use the annotations to validate the call client side before sending it, and you can implement the same interface on the server: @Controller("/pets") public class PetController implements PetOperations { @Override @SingleResult public Publisher<Pet> save(String name, int age) { Pet pet = new Pet(); pet.setName(name); pet.setAge(age); // save to database or something return Mono.just(pet); } } where the same validations will occur before the call is accepted.