REST API Codegenerator Maven Plugin
Are you sick of always having to implement and maintain the client-side services for reaching your Rest API. With the REST API Codegenerator Maven Plugin you are able to automatically generate the client-side code to reach your API.
For now the plugin scans your code for Jersey resources and generates java code - see example of usage in the akka-persistence-java-example-project. In my next project I will extend the plugin to generate ReactJS code aswell.
If you find the plugin useful please give it a star. Also feel free to create pull requests and extend the plugin to generate for example Ajax, AngularJS or ReactJS code.
How to use the plugin for generating Java code
- Add the plugin to your
pom.xmlfile, see example below.
mvn clean installin your project folder
- The plugin will scan your source code and generate code out of your resource classes.
generatedCodeFolder: This is the folder where you want your generated code
generatedCodePackage: This is the package of your generated class files
rootHost: This is the host of your running application
<plugin> <groupId>no.jansoren</groupId> <artifactId>restapi-codegen-maven-plugin</artifactId> <version>1.0.0-SNAPSHOT</version> <configuration> <generatedCodeFolder>../server-qtest/src/main/java</generatedCodeFolder> <generatedCodePackage>com.example.qtest.services</generatedCodePackage> <rootHost>http://localhost:8080</rootHost> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>codegen</goal> </goals> </execution> </executions> </plugin>
<dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> <version>2.23.2</version> </dependency>
If you are using
MediaType.APPLICATION_JSON_TYPE you also need this dependency
<dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-json-jackson</artifactId> <version>2.13.2</version> </dependency>
Example of generating ReactJS code
Not implemented yet
How to get started developing
- Clone this repo
git clone email@example.com:jansoren/restapi-codegen-maven-plugin.git
mvn clean installin the
- The unit tests have now generated some example code at /src/test/java/com/example/helloworld/MyService.java
Why this plugin
Over the years I have created a few REST API's, and I always end up using a lot of time implementing the client-side code for reaching the API's. In one of the projects we had a Quality-test application implemented in java that ran tests continuously, something that required updating the client-side code rapidly. With this challenge we ended up creating a lot of the same boilerplate code for each new service we implemented, and it felt like this code should and could be automatically generated.
In the pursuit of finding such a product I ended up creating a plugin to solve my current need. The result became this plugin.
I hope this can be useful for others as well.