Re:Rust Is Eating JavaScript
by agumonkey on Sunday February 16, 2025 @09:47AM
(#43068439)
and what kind of library / ide plugin is used to call rest api in a type safe manner without writing boilerplate ?
[ Parent
| on HN ]
Re:Rust Is Eating JavaScript
by mike_hearn on Sunday February 16, 2025 @12:48PM
(#43069972)
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.thanks