Skip to content

Commit 3ad04c0

Browse files
authored
Add method to get JSON responses (#129)
Add support for JSON API calls with new method callApiJSON. Backgound: The new method callApiJSON allows java client API users to request a JSON response. We now also can create/build JSON models (e.g. with/for GSON) further enhancing the APIs usability. Signed-off-by: daivdwe <63723761+daivdwe@users.noreply.github.com>
1 parent 6d4b09b commit 3ad04c0

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- Add support for JSON API calls with new method `callApiJson`.
810

911
## [1.15.0] - 2025-01-20
1012
### Added
@@ -233,4 +235,4 @@ of the alert (zaproxy/zaproxy#1341), older methods were deprecated.
233235
[1.2.0]: https://github.com/zaproxy/zap-api-java/compare/v1.1.1...v1.2.0
234236
[1.1.1]: https://github.com/zaproxy/zap-api-java/compare/v1.1.0...v1.1.1
235237
[1.1.0]: https://github.com/zaproxy/zap-api-java/compare/v1.0.0...v1.1.0
236-
[1.0.0]: https://github.com/zaproxy/zap-api-java/compare/6c778f77a817e1ff71e9279e4759535d482e8393...v1.0.0
238+
[1.0.0]: https://github.com/zaproxy/zap-api-java/compare/6c778f77a817e1ff71e9279e4759535d482e8393...v1.0.0

subprojects/zap-clientapi/src/main/java/org/zaproxy/clientapi/core/ClientApi.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,27 @@ public byte[] callApiOther(
472472
String method,
473473
Map<String, String> params)
474474
throws ClientApiException {
475+
return getBytes(requestMethod, "other", component, type, method, params);
476+
}
477+
478+
public String callApiJson(
479+
String component, String type, String method, Map<String, String> params)
480+
throws ClientApiException {
481+
byte[] json = getBytes(HttpRequest.GET_METHOD, "JSON", component, type, method, params);
482+
return new String(json, StandardCharsets.UTF_8);
483+
}
484+
485+
private byte[] getBytes(
486+
String requestMethod,
487+
String format,
488+
String component,
489+
String type,
490+
String method,
491+
Map<String, String> params)
492+
throws ClientApiException {
475493
try {
476494
HttpRequest request =
477-
buildZapRequest(requestMethod, "other", component, type, method, params);
495+
buildZapRequest(requestMethod, format, component, type, method, params);
478496
if (debug) {
479497
debugStream.println("Open URL: " + request.getRequestUri());
480498
}

0 commit comments

Comments
 (0)