Skip to content

Commit 036dc9b

Browse files
📝 Document logging
- document logging (example and config) - update release notes for 3.3.0 - replace search.maven.org with central.sonatype.com - replace Maven-specific instructions with a link to Maven central snippets - remove redundant hyperlinks
1 parent f0f94e7 commit 036dc9b

File tree

1 file changed

+39
-45
lines changed

1 file changed

+39
-45
lines changed

README.md

+39-45
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ limitations under the License.
2222
* [Intro](#intro)
2323
* [Changelog](#changelog)
2424
* [Usage](#usage)
25-
* [Maven](#maven)
26-
* [Request examples](#requests)
25+
* [Request examples](#request-examples)
2726
* [Supported HTTP methods](#http-methods)
2827
* [A request to an arbitrary url](#url)
2928
* [Base url](#base-url)
@@ -38,12 +37,12 @@ limitations under the License.
3837
* [Response body](#response-body)
3938
* [Deserializing JSON responses to Java objects](#jsons)
4039
* [Deserializing JSON responses to Java generics](#generics)
40+
* [Logging](#logging)
4141
* [Future work](#todo)
4242
* [Known bugs](#bugs)
4343
* [Contact](#contact)
4444
* [Disclaimer](#disclaimer)
4545

46-
<a id='intro'></a>
4746
## Intro
4847
This client wraps around [Apache HttpClient](https://hc.apache.org/httpcomponents-client-ga/) and [Jackson Databind](https://github.com/FasterXML/jackson-databind) libraries providing lean Groovy syntax:
4948
```groovy
@@ -87,55 +86,46 @@ class IceCreamTest {
8786
```
8887
Full Java API reference is available [here](doc/JAVA.md)
8988

90-
<a id='changelog'></a>
9189
## Changelog
92-
**[(draft) 3.3.0](https://search.maven.org/artifact/com.tomtom.http/goji-http-client/3.3.0/jar)**: (chore) migrate to [org.wiremock](https://central.sonatype.com/artifact/org.wiremock/wiremock) & [httclient5](https://central.sonatype.com/artifact/org.apache.httpcomponents.client5/httpclient5)
90+
**[3.3.0](https://search.maven.org/artifact/com.tomtom.http/goji-http-client/3.3.0)**:
91+
* (feat) [logging](#logging)
92+
* (chore) migrate to [org.wiremock](https://central.sonatype.com/artifact/org.wiremock/wiremock) & [httclient5](https://central.sonatype.com/artifact/org.apache.httpcomponents.client5/httpclient5)
9393

94-
**[3.2.0](https://search.maven.org/artifact/com.tomtom.http/goji-http-client/3.2.0/jar)**: (feat) default headers
94+
**[3.2.0](https://central.sonatype.com/artifact/com.tomtom.http/goji-http-client/3.2.0)**: (feat) default headers
9595

96-
**[3.1.1](https://search.maven.org/artifact/com.tomtom.http/goji-http-client/3.1.1/jar)**: (security) remove vulnerable dependencies
96+
**[3.1.1](https://central.sonatype.com/artifact/com.tomtom.http/goji-http-client/3.1.1)**: (security) remove vulnerable dependencies
9797

98-
**[3.1.0](https://search.maven.org/artifact/com.tomtom.http/goji-http-client/3.1.0/jar)**: (feat) query parameter support
98+
**[3.1.0](https://central.sonatype.com/artifact/com.tomtom.http/goji-http-client/3.1.0)**: (feat) query parameter support
9999

100-
**[3.0.0](https://search.maven.org/artifact/com.tomtom.http/goji-http-client/3.0.0/jar)**: (chore) Groovy 4 and other dependency updates
100+
**[3.0.0](https://central.sonatype.com/artifact/com.tomtom.http/goji-http-client/3.0.0)**: (chore) Groovy 4 and other dependency updates
101101

102-
**[2.0.0](https://search.maven.org/artifact/com.tomtom.http/goji-http-client/2.0.0/jar)**: (feature) Java-friendly API
102+
**[2.0.0](https://central.sonatype.com/artifact/com.tomtom.http/goji-http-client/2.0.0)**: (feature) Java-friendly API
103103

104-
**[1.4.0](https://search.maven.org/artifact/com.tomtom.http/goji-http-client/1.4.0/jar)**: (chore) updated dependencies, including Groovy v2 -> v3 and Jackson (addressing [CVE-2019-17531](https://github.com/advisories/GHSA-gjmw-vf9h-g25v))
104+
**[1.4.0](https://central.sonatype.com/artifact/com.tomtom.http/goji-http-client/1.4.0)**: (chore) updated dependencies, including Groovy v2 -> v3 and Jackson (addressing [CVE-2019-17531](https://github.com/advisories/GHSA-gjmw-vf9h-g25v))
105105

106-
**[1.3.1](https://search.maven.org/artifact/com.tomtom.http/goji-http-client/1.3.1/jar)**: (chore) updated dependencies, including jackson-databind version with vulnerabilities
106+
**[1.3.1](https://central.sonatype.com/artifact/com.tomtom.http/goji-http-client/1.3.1)**: (chore) updated dependencies, including jackson-databind version with vulnerabilities
107107

108-
**[1.3.0](https://search.maven.org/artifact/com.tomtom.http/goji-http-client/1.3.0/jar)**: (feat) file upload
108+
**[1.3.0](https://central.sonatype.com/artifact/com.tomtom.http/goji-http-client/1.3.0)**: (feat) file upload
109109

110-
**[1.2.3](https://search.maven.org/artifact/com.tomtom.http/goji-http-client/1.2.3/jar)**: (chore) updated dependencies, including jackson-databind version with vulnerabilities
110+
**[1.2.3](https://central.sonatype.com/artifact/com.tomtom.http/goji-http-client/1.2.3)**: (chore) updated dependencies, including jackson-databind version with vulnerabilities
111111

112-
**[1.2.0](https://search.maven.org/artifact/com.tomtom.http/goji-http-client/1.2.0/jar)**: (feature) support for TRACE, OPTIONS and PATCH methods
112+
**[1.2.0](https://central.sonatype.com/artifact/com.tomtom.http/goji-http-client/1.2.0)**: (feature) support for TRACE, OPTIONS and PATCH methods
113113

114-
**[1.1.0](https://search.maven.org/artifact/com.tomtom.http/goji-http-client/1.1.0/jar)**: (doc) maven usage and javadocs
114+
**[1.1.0](https://central.sonatype.com/artifact/com.tomtom.http/goji-http-client/1.1.0)**: (doc) maven usage and javadocs
115115

116-
**[1.0.0](https://search.maven.org/artifact/com.tomtom.http/goji-http-client/1.0.0/jar)**: initial release
116+
**[1.0.0](https://central.sonatype.com/artifact/com.tomtom.http/goji-http-client/1.0.0)**: initial release
117117

118-
<a id='usage'></a>
119118
## Usage
120119

121120
GOJI HTTP uses the [semantic versioning](http://semver.org/) strategy: MAJOR.MINOR.PATCH.
122121

123-
<a id='maven'></a>
124-
### Maven
125-
126-
```xml
127-
<dependency>
128-
<groupId>com.tomtom.http</groupId>
129-
<artifactId>goji-http-client</artifactId>
130-
<version>3.2.0</version>
131-
</dependency>
132-
```
122+
Check [Maven central repository](https://central.sonatype.com/artifact/com.tomtom.http/goji-http-client/3.3.0) for snippets to add the client as a dependency for your build system.
133123

134124
<a id='requests'></a>
135125
## Request examples
136126

137127
<a id='http-methods'></a>
138-
### Supported HTTP methods:
128+
### Supported HTTP methods
139129

140130
`GET`, `POST`, `PUT` and `DELETE` are supported:
141131
```groovy
@@ -149,14 +139,13 @@ http.options()
149139
```
150140

151141
<a id='url'></a>
152-
### A request to an arbitrary url:
142+
### A request to an arbitrary url
153143

154144
```groovy
155145
http.get(url: 'http://pizza-delivery.org/margheritas')
156146
```
157147

158-
<a id='base-url'></a>
159-
### Base url:
148+
### Base url
160149

161150
If you want to make a number of requests to a given service, you can specify the `baseUrl` constructor parameter:
162151
```groovy
@@ -165,8 +154,7 @@ def http = new HttpClient(baseUrl: 'http://water-melon.com')
165154
http.get(path: '/slice')
166155
```
167156

168-
<a id='query'></a>
169-
### Query:
157+
### Query
170158

171159
You can either specify a query in `url` or `path`, or via `query` parameter:
172160

@@ -180,8 +168,7 @@ http.put(path: '/put', query: [some: 'query', other: ['one', 'two']])
180168

181169
> _NB!_ if `url` or `path` contains a query already, `query` parameter is ignored.
182170
183-
<a id='request-headers'></a>
184-
### Request headers:
171+
### Request headers
185172

186173
```groovy
187174
http.put(
@@ -191,8 +178,7 @@ http.put(
191178
'Content-Type': 'application/json'])
192179
```
193180

194-
<a id='default-headers'></a>
195-
#### Default headers:
181+
#### Default headers
196182

197183
Default headers are sent with each request. It is also possible to override default headers per request:
198184

@@ -203,8 +189,7 @@ def http = new HttpClient(defaultHeaders: [
203189
http.put(path: '/put', headers: ['Content-Type': 'application/xml'])
204190
```
205191

206-
<a id='request-body'></a>
207-
### Request body:
192+
### Request body
208193

209194
Any non-string body is serialized as JSON.
210195

@@ -243,7 +228,6 @@ def response = http.get(path: '/get')
243228
assert response.statusCode == ResponseCode.OK
244229
```
245230

246-
<a id='response-headers'></a>
247231
### Response headers
248232

249233
```groovy
@@ -256,7 +240,6 @@ assert response.headers == [
256240
Connection: 'keep-alive']
257241
```
258242

259-
<a id='response-body'></a>
260243
### Response body
261244

262245
By default, the response body is a String:
@@ -301,12 +284,25 @@ assert response.body == [
301284

302285
See more use-cases in [tests](src/test/groovy)
303286

287+
## Logging
288+
289+
The client uses [log4j v2](https://logging.apache.org/log4j/2.x/), sample output:
290+
```
291+
2023-09-23 14:54:20 INFO POST http://localhost:53611/freezer
292+
2023-09-23 14:54:20 INFO headers: [shelve: top]
293+
2023-09-23 14:54:20 INFO body: ice-cream
294+
2023-09-23 14:54:20 INFO => response: 200
295+
2023-09-23 14:54:20 INFO headers: [Content-Type: application/json]
296+
2023-09-23 14:54:20 INFO body: {"contents": ["ice-cream"]}
297+
```
298+
299+
Example configuration can be found [here](./src/test/resources/log4j2.xml).
300+
304301
<a id='todo'></a>
305302
## Future work
306303

307304
- Verify HTTPS certificates
308305
- Document URL encoding behavior
309-
- Allow specifying `Authorization` header in constructor
310306

311307
<a id='bugs'></a>
312308
## Known bugs
@@ -331,12 +327,10 @@ And release (when successful):
331327
mvn nexus-staging:release
332328
```
333329

334-
<a id='contact'></a>
335330
## Contact
336331

337332
[artamonov.kirill@gmail.com](mailto:artamonov.kirill@gmail.com)
338333

339-
<a id="disclaimer"></a>
340334
## Disclaimer
341335

342336
Our primary use-case of this http client is testing our REST services. The client has not been tested for any production use though we don't expect big issues there.

0 commit comments

Comments
 (0)