Rest Client Generator

Java annotation processor for the implementation of rest calls.

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

io.github.raphasil.rest-client-generator
ArtifactId

ArtifactId

resttemplate-processor
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Rest Client Generator
Java annotation processor for the implementation of rest calls.
Project URL

Project URL

https://raphasil.github.io/rest-client-generator
Source Code Management

Source Code Management

https://github.com/raphasil/rest-client-generator

Download resttemplate-processor

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.raphasil.rest-client-generator/resttemplate-processor/ -->
<dependency>
    <groupId>io.github.raphasil.rest-client-generator</groupId>
    <artifactId>resttemplate-processor</artifactId>
    <version>0.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.raphasil.rest-client-generator/resttemplate-processor/
implementation 'io.github.raphasil.rest-client-generator:resttemplate-processor:0.0.1'
// https://jarcasting.com/artifacts/io.github.raphasil.rest-client-generator/resttemplate-processor/
implementation ("io.github.raphasil.rest-client-generator:resttemplate-processor:0.0.1")
'io.github.raphasil.rest-client-generator:resttemplate-processor:jar:0.0.1'
<dependency org="io.github.raphasil.rest-client-generator" name="resttemplate-processor" rev="0.0.1">
  <artifact name="resttemplate-processor" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.raphasil.rest-client-generator', module='resttemplate-processor', version='0.0.1')
)
libraryDependencies += "io.github.raphasil.rest-client-generator" % "resttemplate-processor" % "0.0.1"
[io.github.raphasil.rest-client-generator/resttemplate-processor "0.0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-web jar

runtime (4)

Group / Artifact Type Version
io.github.raphasil.rest-client-generator : core jar 0.0.1
com.squareup : javapoet jar
com.google.auto : auto-common jar
org.apache.commons : commons-lang3 jar

test (2)

Group / Artifact Type Version
com.google.testing.compile : compile-testing jar
org.junit.jupiter : junit-jupiter jar

Project Modules

There are no modules declared in this project.

Rest Client Generator

Maven Central License

Build Status codecov Code Quality: Java Total Alerts

Introduction

RestClientGenerator is a Java annotation processor for the implementation of rest calls

Getting Started

Take a look here.

API Declaration

Annotations on the interface methods and its parameters indicate how a request will be handled.

Request Method

Every method must have an HTTP annotation that provides the request method and relative path. There are eight built-in annotations: HTTP, GET, POST, PUT, PATCH, DELETE, OPTIONS and HEAD. The relative path of the resource can be defined in the annotation.

@RestClient("client-one")
interface UserService {
    @GET("api/v1/users")
    List getUsers();
}

URL Manipulation

A request URL can be updated dynamically using replacement blocks and parameters on the method. A replacement block is an alphanumeric string surrounded by { and }. A corresponding parameter must be annotated with @Path using the same string or variable name.

@RestClient(value = "client-one", path = "api/v1/users")
interface UserService {
    
    @GET("{id}")
    User getUserById(@Path UUID id);
    
    @GET("api/v1/users/{id}/profiles/{profile-id}")
    User getUserProfile(@Path UUID id, @Path("profile-id") String profileId);

}

A query parameter can also be added:

@RestClient("client-one")
interface UserService {
    
    // result: api/v1/users?sort=""&nickname=""
    @GET("api/v1/users")
    List<User> getAll(@Query String sort, @Query("nickname") String name);

}

Request Body

An object can be specified for use as an HTTP request body with the @Body annotation.

@RestClient("client-one")
interface UserService {
        
    @POST("api/v1/users")
    User create(@Body User user);

}

Header Manipulation

You can set static headers for a method using the @Headers annotation.

@RestClient("client-one")
interface UserService {
    
    @Headers("x-ping: pong")    
    @POST("api/v1/users")
    User create(@Body User user);
    
    @Headers({
                 "Accept: application/txt",
                 "x-api-key: secret"
             })    
    @PUT("api/v1/users")
    User create(@Body User user);
    
    @GET("api/v1/users")
    User getUser(@Header("Authorization") String admin);

}

Versions

Version
0.0.1