-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava-httpclient.java
More file actions
27 lines (26 loc) · 1.07 KB
/
Copy pathjava-httpclient.java
File metadata and controls
27 lines (26 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Render a ZPL file to PNG via the Labelixa REST API (Java 11+,
// java.net.http — no dependencies).
// Free tier needs no key and output carries NO watermark; set the
// X-API-Key header to use your own quota.
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Path;
public class RenderLabel {
public static void main(String[] args) throws Exception {
HttpClient http = HttpClient.newHttpClient();
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create(
"https://api.labelixa.com/v1/printers/8dpmm/labels/4x6/0"))
// .header("X-API-Key", "lbx_...")
.POST(HttpRequest.BodyPublishers.ofFile(
Path.of("../examples/shipping-label-4x6.zpl")))
.build();
HttpResponse<Path> resp = http.send(
req, HttpResponse.BodyHandlers.ofFile(Path.of("label.png")));
if (resp.statusCode() != 200) {
throw new RuntimeException("HTTP " + resp.statusCode());
}
}
}