Skip to content

Commit 38b7c19

Browse files
authored
docs: http on README (#60)
Signed-off-by: Edoardo Vacchi <[email protected]>
1 parent e8e56a4 commit 38b7c19

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,92 @@ System.out.println(output);
182182
// => {"count": 3, "total": 3, "vowels": "aeiouAEIOU"}
183183
```
184184

185+
## HTTP and JSON Support
186+
187+
The HTTP and JSON interfaces are an optional dependency. For convenience, we provide a common set of config choices, but you can plug your own.
188+
189+
## Predefined Java Config (Java 11+ HTTP Client + Jackson JSON):
190+
191+
```xml
192+
<dependency>
193+
<groupId>org.extism.sdk</groupId>
194+
<artifactId>http-config-generic</artifactId>
195+
<version>999-SNAPSHOT</version>
196+
</dependency>
197+
```
198+
199+
then configure:
200+
201+
```java
202+
var manifest = Manifest.ofWasms(wasm)
203+
.withOptions(new Manifest.Options().withHttpConfig(GenericHttpConfig.get()))
204+
.build();
205+
```
206+
207+
## Predefined Android Config (URLConnection + Jackson JSON):
208+
209+
```xml
210+
<dependency>
211+
<groupId>org.extism.sdk</groupId>
212+
<artifactId>http-config-android</artifactId>
213+
<version>999-SNAPSHOT</version>
214+
</dependency>
215+
```
216+
217+
then configure:
218+
219+
```java
220+
var manifest = Manifest.ofWasms(wasm)
221+
.withOptions(new Manifest.Options().withHttpConfig(AndroidHttpConfig.get()))
222+
.build();
223+
```
224+
225+
### Customizing HTTP and JSON Support
226+
227+
The Chicory SDK exposes HTTP clients and JSON support through 2 thin interfaces.
228+
229+
**HTTP** (`org.extism.sdk.chicory.http.HttpClientAdapter`) with 2 default implementations:
230+
231+
- `org.extism.sdk:http-client-javanet`: uses `java.net.http.HttpClient`
232+
- `org.extism.sdk:http-client-urlconnection`: uses `java.net.HttpURLConnection`
233+
234+
**JSON** (`org.extism.sdk.chicory.http.HttpJsonCodec`) with 2 default implementations:
235+
236+
- `org.extism.sdk:http-json-jackson`: uses the Jackson library
237+
- `org.extism.sdk:http-json-jakarta`: uses the lightweight `jakarta.json.Json` interfaces
238+
239+
For instance, to use `org.extism.sdk:http-client-javanet` with `org.extism.sdk:http-json-jackson`
240+
you could explicitly add the dependencies:
241+
242+
```xml
243+
<dependency>
244+
<groupId>org.extism.sdk</groupId>
245+
<artifactId>http-client-javanet</artifactId>
246+
<version>999-SNAPSHOT</version>
247+
</dependency>
248+
249+
<dependency>
250+
<groupId>org.extism.sdk</groupId>
251+
<artifactId>http-json-jackson</artifactId>
252+
<version>999-SNAPSHOT</version>
253+
</dependency>
254+
```
255+
256+
Then you can configure them:
257+
258+
```java
259+
var manifest = Manifest.ofWasms(wasm)
260+
.withOptions(
261+
new Manifest.Options()
262+
.withHttpConfig(HttpConfig.builder()
263+
.withClientAdapter(JavaNetHttpClientAdapter::new)
264+
.withJsonCodec(JacksonJsonCodec::new)
265+
.build())).build();
266+
```
267+
268+
Through the same mechanism, you can also load your own custom implementations for
269+
`org.extism.sdk.chicory.http.HttpClientAdapter` and `org.extism.sdk.chicory.http.HttpJsonCodec`.
270+
185271
## Development
186272

187273
# Build

0 commit comments

Comments
 (0)