Skip to content

Latest commit

 

History

History
97 lines (75 loc) · 3.08 KB

README.md

File metadata and controls

97 lines (75 loc) · 3.08 KB

http_client_using_okhttp3

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.

Use case

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.

Requirements

  • Java 8 or later
  • apache-maven-3.6.0 or later
  • okhttp 3.2.0 or later

Building project

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.

Usage

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:

Request explained

Request URL

http://<host>:<port>/restclient/execute

Request Headers

Content-Type : application/json

Request Body

{
  "url": "https://testexternalapi.free.beeceptor.com/my/api/path",
  "requestMethod": "POST",
  "header": {
    "ContentType": "applicaiton/json"
  },
  "queryParams": {},
  "requestBody": {
    "data": "Hello Beeceptor"
  }
}

Request samples

POST request

PUT request

GET request

DELETE request

HEAD request

Contributing

Please raise an issue if you find anything which is not working or want unimplemented functionality.

License

MIT