11package com .retailsvc .http ;
22
3+ import static java .net .HttpURLConnection .HTTP_ACCEPTED ;
4+ import static java .net .HttpURLConnection .HTTP_CREATED ;
5+ import static java .net .HttpURLConnection .HTTP_NOT_FOUND ;
6+ import static java .net .HttpURLConnection .HTTP_NOT_IMPLEMENTED ;
7+ import static java .net .HttpURLConnection .HTTP_NO_CONTENT ;
8+ import static java .net .HttpURLConnection .HTTP_OK ;
9+
310import com .retailsvc .http .internal .BodyWriter ;
411import java .io .IOException ;
512import java .io .OutputStream ;
@@ -33,7 +40,7 @@ public record Response(int status, Object body, String contentType, Map<String,
3340
3441 /** {@code 204 No Content} with no body. */
3542 public static Response empty () {
36- return new Response (204 , null , null , Map .of ());
43+ return new Response (HTTP_NO_CONTENT , null , null , Map .of ());
3744 }
3845
3946 /** Given status, no body. Use for {@code 200 OK} no body, {@code 404}, {@code 405}, etc. */
@@ -45,45 +52,45 @@ public static Response status(int status) {
4552
4653 /** {@code 200 OK} with {@code body} serialised as JSON. */
4754 public static Response ok (Object body ) {
48- return new Response (200 , body , null , Map .of ());
55+ return new Response (HTTP_OK , body , null , Map .of ());
4956 }
5057
5158 /** {@code 201 Created} with {@code body} serialised as JSON. */
5259 public static Response created (Object body ) {
53- return new Response (201 , body , null , Map .of ());
60+ return new Response (HTTP_CREATED , body , null , Map .of ());
5461 }
5562
5663 /**
5764 * {@code 201 Created} with {@code body} as JSON and a {@code Location} header — the canonical
5865 * shape for a POST that creates a new resource.
5966 */
6067 public static Response created (Object body , String location ) {
61- return new Response (201 , body , null , Map .of ("Location" , location ));
68+ return new Response (HTTP_CREATED , body , null , Map .of ("Location" , location ));
6269 }
6370
6471 /** {@code 202 Accepted} with no body. Use for fire-and-forget async work. */
6572 public static Response accepted () {
66- return new Response (202 , null , null , Map .of ());
73+ return new Response (HTTP_ACCEPTED , null , null , Map .of ());
6774 }
6875
6976 /** {@code 202 Accepted} with {@code body} serialised as JSON (typically a job/poll URL). */
7077 public static Response accepted (Object body ) {
71- return new Response (202 , body , null , Map .of ());
78+ return new Response (HTTP_ACCEPTED , body , null , Map .of ());
7279 }
7380
7481 /** {@code 404 Not Found} with no body. */
7582 public static Response notFound () {
76- return new Response (404 , null , null , Map .of ());
83+ return new Response (HTTP_NOT_FOUND , null , null , Map .of ());
7784 }
7885
7986 /** {@code 404 Not Found} with {@code body} serialised as JSON (e.g. a ProblemDetail). */
8087 public static Response notFound (Object body ) {
81- return new Response (404 , body , null , Map .of ());
88+ return new Response (HTTP_NOT_FOUND , body , null , Map .of ());
8289 }
8390
8491 /** {@code 501 Not Implemented} with no body. */
8592 public static Response notImplemented () {
86- return new Response (501 , null , null , Map .of ());
93+ return new Response (HTTP_NOT_IMPLEMENTED , null , null , Map .of ());
8794 }
8895
8996 /** {@code status} with {@code body} serialised by the content-type's {@link TypeMapper}. */
0 commit comments