3 ms·
Most frameworks will do that? In Micronaut it's something like this on the client: @Validated public interface PetOperations { @Post @S
by mike_hearn 2y ago
Most 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.