Skip to content

Commit 10a05eb

Browse files
committed
feat: Add Response.accepted() / accepted(body) factories
1 parent a17aef7 commit 10a05eb

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Response.empty(); // 204 No Content, no body
6262
Response.status(404); // 404, no body
6363
Response.status(200); // 200 OK, no body
6464
Response.ok(Map.of("id", "42")); // 200 OK, JSON body via TypeMapper
65+
Response.accepted(); // 202 Accepted, no body
66+
Response.accepted(Map.of("jobId", "job-42")); // 202 Accepted, JSON body
6567
Response.of(201, newResource); // any status, JSON body
6668
Response.text(200, "hello"); // text/plain; UTF-8
6769
Response.bytes(200, pdf, "application/pdf"); // pre-serialised bytes

src/main/java/com/retailsvc/http/Response.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ public static Response ok(Object body) {
4848
return new Response(200, body, null, Map.of());
4949
}
5050

51+
/** {@code 202 Accepted} with no body. Use for fire-and-forget async work. */
52+
public static Response accepted() {
53+
return new Response(202, null, null, Map.of());
54+
}
55+
56+
/** {@code 202 Accepted} with {@code body} serialised as JSON (typically a job/poll URL). */
57+
public static Response accepted(Object body) {
58+
return new Response(202, body, null, Map.of());
59+
}
60+
5161
/** {@code status} with {@code body} serialised by the content-type's {@link TypeMapper}. */
5262
public static Response of(int status, Object body) {
5363
return new Response(status, body, null, Map.of());

0 commit comments

Comments
 (0)