A spring-boot application which can execute an external API calls for GET, PUT, POST, DELETE and HEAD http methods. It uses Okhttp java library.
If you want to call external rest APIs inside your Java project then you can use this project for your work, The project has exposed an endpoint which can be used to call any external rest api.
- Java 8 or later
- apache-maven-3.6.0 or later
- okhttp 3.2.0 or later
Its an standard maven project , which you can open in eclipse or intellij IDE by importing pom.xml file. Once opened in IDE , just build the project using below maven command
mvn clean install
you can also run sonar in this project using below command
mvn jacoco:prepare-agent test jacoco:report
and then
mvn sonar:sonar
but for that you should have sonar install and started in your system and settings.xml which is pointing to your local sonar instance. You can ignore above two commands if you just want the okhttp client.
Once maven build is successful, the application will run on default port of 8080
. You can change it by changing/creating the entry inside resources/application.properties as below
server.port=8080
Once it is done , you can start the application. From here you can either go to swagger documentation or use postman to hit the request. Below is the url for swagger documentation
http://localhost:8080/swagger-ui.html
This is how the swagger request will looks like:
http://<host>:<port>/restclient/execute
Content-Type : application/json
{
"url": "https://testexternalapi.free.beeceptor.com/my/api/path",
"requestMethod": "POST",
"header": {
"ContentType": "applicaiton/json"
},
"queryParams": {},
"requestBody": {
"data": "Hello Beeceptor"
}
}
Please raise an issue if you find anything which is not working or want unimplemented functionality.