Skip to content

Commit 1d2fb88

Browse files
Update README.md
1 parent 1be3db9 commit 1d2fb88

File tree

1 file changed

+49
-32
lines changed

1 file changed

+49
-32
lines changed

README.md

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,70 @@
1-
# Simple HTTP Wrapper
1+
# Simple HTTP Wrapper (SimpleHTTPWrapper)
2+
Author: LightLibs
3+
License: MIT
24

3-
This code provides a simple HTTP wrapper for making GET and POST requests. It includes classes and methods to perform HTTP requests and handle the response.
5+
This library provides a simple HTTP wrapper for making GET, POST, and other requests. It includes classes and methods to
6+
perform HTTP requests and handle the response.
47

5-
## SimpleHttpResponse
8+
## HttpResponse
69

7-
The `SimpleHttpResponse` class represents the response from an HTTP request. It contains the following methods:
10+
The `HttpResponse` class represents the response from an HTTP request. It contains the following methods:
811

912
- `getStatusCode()`: Returns the status code of the response.
10-
- `getData()`: Returns the data (response body) of the response.
13+
- `getHeaders()`: Returns the headers of the response.
14+
- `getBody()`: Returns the body (response data) of the response.
1115

12-
## SimpleHttpWrapper
16+
## HttpWrapper
1317

14-
The `SimpleHttpWrapper` class provides static methods to make HTTP requests. It includes the following methods:
18+
The `HttpWrapper` class provides static methods to make HTTP requests. It includes the following methods (and more):
1519

16-
- `get(String urlStr, String[] headers)`: Performs a GET request to the specified URL with optional headers and returns a `SimpleHttpResponse`.
17-
- `post(String urlStr, String[] headers, String postData)`: Performs a POST request to the specified URL with optional headers and post data, and returns a `SimpleHttpResponse`.
18-
- `performRequest(SupportedHttpMethod method, String urlStr, String[] headers, String postData)`: Performs an HTTP request with the specified method (GET or POST), URL, headers, and post data. Returns a `SimpleHttpResponse`.
19-
- `performRequestUnsupported(String method, String urlStr, String[] headers, String postData)`: Discouraged method for performing an HTTP request with an unsupported method. Returns a `SimpleHttpResponse`.
20+
- `get(String urlStr, String[] headers)`: Performs a GET request to the specified URL with optional headers and returns
21+
a `SimpleHttpResponse`.
22+
- `post(String urlStr, String[] headers, String postData)`: Performs a POST request to the specified URL with
23+
optionalheaders and post data, and returns a `SimpleHttpResponse`.
24+
- `performRequest(SupportedHttpMethod method, String urlStr, String[] headers, String postData)`: Performs an HTTP
25+
request with the specified method (GET or POST), URL, headers, and post data. Returns a `SimpleHttpResponse`.
26+
- `performRequestUnsupported(String method, String urlStr, String[] headers, String postData)`: Discouraged method for
27+
performing an HTTP request with an unsupported method. Returns a `SimpleHttpResponse`.
2028

21-
## SupportedHttpMethod
29+
## HttpMethod
2230

23-
The `SupportedHttpMethod` enum defines the supported HTTP methods. It includes the following methods:
31+
The `HttpMethod` enum defines the supported HTTP methods. It includes the following methods:
2432

25-
- `getRawMethodName()`: Returns the raw method name as a `String`.
33+
- `getMethodId()`: Returns the raw method name as a `String`.
2634

2735
## Usage
2836

29-
To use the `SimpleHttpWrapper` class, import the `com.github.lightlibs.simplehttpwrapper` package and call the desired static methods. For example:
37+
To use the `HttpWrapper` class, import the `com.github.lightlibs.simplehttpwrapper` package and call the desired static
38+
methods. For example:
3039

3140
```java
41+
import com.github.lightlibs.simplehttpwrapper.HttpHeader;
3242
import com.github.lightlibs.simplehttpwrapper.HttpResponse;
3343
import com.github.lightlibs.simplehttpwrapper.HttpWrapper;
3444
import com.github.lightlibs.simplehttpwrapper.SimpleHttpWrapper;
3545

3646
class Example {
3747

38-
public static void main(String[] args) {
39-
// Perform a GET request
40-
HttpResponse response = HttpWrapper.get("https://example.com", null);
41-
int statusCode = response.getStatusCode();
42-
String data = response.getBody();
43-
44-
// Perform a POST request with headers and post data
45-
String[] headers = {"Content-Type: application/json"};
46-
String postData = "{ \"name\": \"John\", \"age\": 30 }";
47-
HttpResponse response = HttpWrapper.post("https://example.com", headers, postData);
48-
int statusCode = response.getStatusCode();
49-
String data = response.getBody();
50-
}
48+
public static void main(String[] args) {
49+
// Perform a GET request
50+
HttpResponse response = HttpWrapper.get("https://example.com", null);
51+
int statusCode = response.getStatusCode();
52+
String data = response.getBody();
53+
54+
// Perform a POST request with headers and post data
55+
String[] headers = {"Content-Type: application/json"};
56+
String postData = "{ \"name\": \"John\", \"age\": 30 }";
57+
58+
// Make the request
59+
HttpResponse response = HttpWrapper.post("https://example.com", headers, postData);
60+
// Alternative request which doesn't throw an IOException
61+
HttpResponse responseOrNull = HttpWrapper.postOrNull("https://example.com", headers, postData);
62+
63+
// Read the response from the server
64+
int statusCode = response.getStatusCode();
65+
List<HttpHeader> responseHeaders = response.getHeaders();
66+
String responseBody = response.getBody();
67+
}
5168

5269
}
5370
```
@@ -62,7 +79,7 @@ class Example {
6279

6380
```groovy
6481
dependencies {
65-
implementation 'com.github.lightlibs:simplehttpwrapper:[VERSION-STRING]'
82+
implementation 'com.github.lightlibs:SimpleHttpWrapper:0.0.5'
6683
}
6784
```
6885

@@ -79,11 +96,11 @@ class Example {
7996
```xml
8097
<dependency>
8198
<groupId>com.github.lightlibs</groupId>
82-
<artifactId>simplehttpwrapper</artifactId>
83-
<version>[VERSION-STRING]</version>
99+
<artifactId>SimpleHttpWrapper</artifactId>
100+
<version>0.0.5</version>
84101
</dependency>
85102
```
86103

87-
Note: Make sure to handle `IOException` when making the requests.
104+
Note: Make sure to catch any `IOException` when making the requests.
88105

89106
Feel free to customize the code or add additional functionality as needed. And make a PR ;)

0 commit comments

Comments
 (0)