Appendix: Low-level HTTP Requests#
In addition to the high-level APIs .create()
, .read()
,
.update()
, .delete()
, to perform
low-level HTTP requests, the Java Client Libraries include:
Request.Builder to build HTTP requests.
Request.BodyPublishers to handle request body payloads.
.send()
method in SolidSyncClient and SolidClient to send the request.Response.BodyHandlers to handle response body payloads.
For example, the following uses the Java Client Library to create a
PUT
request to save a file to a Pod and send the request:
import com.inrupt.client.Request;
import com.inrupt.client.Response;
import java.io.InputStream;
import java.io.IOException;
//...
// MultipartFile file = ...
try (final var fileStream = file.getInputStream()) {
Request request = Request.newBuilder()
.uri(URI.create("https://storage.example.com/some/resource"))
.header("Content-Type", file.getContentType())
.PUT(Request.BodyPublishers.ofInputStream(fileStream))
.build();
Response<Void> response = client.send(
request,
Response.BodyHandlers.discarding());
} catch (IOException e1) {
e1.printStackTrace();
}