Package com.guinetik.rr.request
Class RequestSpec<Req,Res>
- java.lang.Object
-
- com.guinetik.rr.request.RequestSpec<Req,Res>
-
- Type Parameters:
Req- the type of the request body (useVoidfor requests without body)Res- the type of the expected response
public class RequestSpec<Req,Res> extends Object
Immutable specification of an HTTP request containing all parameters needed for execution.A
RequestSpecencapsulates the complete definition of an API request including the endpoint, HTTP method, query parameters, headers, request body, and expected response type. Instances are created using theRequestBuilderfluent API.Request Components
- Endpoint - The API path (relative or absolute URL)
- Method - HTTP method (GET, POST, PUT, DELETE, etc.)
- Query Parameters - URL query string parameters
- Headers - HTTP request headers via
RocketHeaders - Body - Request payload (for POST, PUT, PATCH)
- Response Type - Expected Java class for response deserialization
Creating Request Specifications
// Simple GET request RequestSpec<Void, User> getUser = RequestBuilder.<Void, User>get("/users/1") .responseType(User.class) .build(); // POST request with body CreateUserRequest body = new CreateUserRequest("John", "john@example.com"); RequestSpec<CreateUserRequest, User> createUser = RequestBuilder .<CreateUserRequest, User>post("/users") .body(body) .responseType(User.class) .build(); // GET with query parameters Map<String, String> params = new HashMap<>(); params.put("page", "1"); params.put("limit", "20"); RequestSpec<Void, UserList> listUsers = RequestBuilder.<Void, UserList>get("/users") .queryParams(params) .responseType(UserList.class) .build();Executing Requests
// With synchronous client User user = client.sync().execute(getUser); // With async client CompletableFuture<User> future = client.async().execute(getUser); // With fluent client Result<User, ApiError> result = client.fluent().execute(getUser);- Since:
- 1.0.0
- Author:
- guinetik <guinetik@gmail.com>
- See Also:
RequestBuilder,RocketHeaders
-
-
Constructor Summary
Constructors Constructor Description RequestSpec(String endpoint, String method, Map<String,String> queryParams, RocketHeaders headers, Req body, Class<Res> responseType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ReqgetBody()StringgetEndpoint()RocketHeadersgetHeaders()StringgetMethod()Map<String,String>getQueryParams()Class<Res>getResponseType()
-