Devops
Devops
Project Overview:
The HTTP Client Application is a standalone Java-based program that provides basic
functionality for sending HTTP GET and POST requests to web APIs. It allows users to
test API endpoints and view responses in a user-friendly console interface.
Key Features:
GET Request: Allows users to send a GET request to a specified URL and receive a response. This
can be useful for retrieving information from APIs or testing API endpoints.
POST Request: Enables users to send data in JSON format to a specified URL using a POST
request. The response from the server is displayed to confirm successful data submission.
Response Display: Displays the API responses in a structured format, showing response data and
status
Project Setup:
Step-by-Step Guide:
Package: com.example.httpclient
Class: HttpClientExample
Functions Implemented:
Sample Code:
Package com.example.httpclient;
Import org.apache.http.HttpEntity;
Import org.apache.http.client.methods.CloseableHttpResponse;
Import org.apache.http.client.methods.HttpGet;
Import org.apache.http.client.methods.HttpPost;
Import org.apache.http.entity.StringEntity;
Import org.apache.http.impl.client.CloseableHttpClient;
Import org.apache.http.impl.client.HttpClients;
Import org.apache.http.util.EntityUtils;
Output Example:
GET Request Example
For a GET request to the URL https://jsonplaceholder.typicode.com/posts/1, the
console output would look like this:GET Request:
Response Code: 200
{
“userId”: 1,
“id”: 1,
“title”: “sunt aut facere repellat provident occaecati excepturi optio
reprehenderit”,
“body”: “quia et suscipit\nsuscipit …
}
OUTPUT