Home > OS >  Quarkus restful Api
Quarkus restful Api

Time:10-01

How to write a rest API with Quarkus, is there any tutorial, the problem is I don't know how to structure a restful API with quarkus, something needs to be formated as architecture

CodePudding user response:

I think what you should do is try to build it with a framework you know like java spring boot, and do similarity with quarkus

CodePudding user response:

Here is an example. From quarkus guides.

@Path("/fruits")
public class FruitResource {

    private Set<Fruit> fruits = Collections.newSetFromMap(Collections.synchronizedMap(new LinkedHashMap<>()));

    public FruitResource() {
        fruits.add(new Fruit("Apple", "Winter fruit"));
        fruits.add(new Fruit("Pineapple", "Tropical fruit"));
    }

    @GET
    public Set<Fruit> list() {
        return fruits;
    }

    @POST
    public Set<Fruit> add(Fruit fruit) {
        fruits.add(fruit);
        return fruits;
    }

    @DELETE
    public Set<Fruit> delete(Fruit fruit) {
        fruits.removeIf(existingFruit -> existingFruit.name.contentEquals(fruit.name));
        return fruits;
    }
}
  • Related