makiftutuncu / Morph-Http-Client

Dynamic Rest Client Via Interfaces

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Morph-Client

Dynamic Rest Client Via Interfaces

Introduction

Sample

Sample Interface

@Path("${baseUrl}")
public interface RegresService {

   @GET
   List<User> getAllUsers();


   @GET
   @Path("/getAsMap")
   Map<Integer, String> getAsMap();

   @PUT
   @Path("/user/{id}")
   @Consumes("application/json")
   @Produces("application/json")
   User updateUser(@PathParam("id") int id, User user);

   @PUT
   @Path("/user/{id}")
   @Consumes("application/json")
   @Produces("application/json")
   String updateUserAsStr(@PathParam("id") int id, User user);

}

Sample Client

  System.setProperty("baseUrl", "http://localhost:8282/api");
 
  MorphClient morphClient =
               MorphClientServiceBuilder.newBuilder()
                       .addMessageConverter(new DefaultJsonMessageConverter())
                       .setPathPropertyResolver(new DefaultSystemEnvironmentPropertyResolver())
                       .build();

  this.regresService = morphClient.morph(RegresService.class);

About

Dynamic Rest Client Via Interfaces

License:Apache License 2.0


Languages

Language:Java 100.0%