Class HttpRequestBuilder
-
- All Implemented Interfaces:
public class HttpRequestBuilder extends HttpPartBuilder
Pact HTTP Request builder DSL that supports V4 formatted Pact files
-
-
Constructor Summary
Constructors Constructor Description HttpRequestBuilder(HttpRequest request)
-
Method Summary
Modifier and Type Method Description final HttpRequestbuild()Terminate the builder and return the request object final HttpRequestBuildermethod(String method)HTTP Method for the request. final HttpRequestBuilderpath(String path)Path for the request. final HttpRequestBuilderpath(Matcher matcher)Sets the path of the request using a matching rule. HttpRequestBuilderheader(String key, Object value)Adds a header to the HTTP part. HttpRequestBuilderheaders(String key, String value, String nameValuePairs)Adds all the headers to the HTTP part. HttpRequestBuilderheaders(Pair<String, Object> nameValuePairs)Adds all the headers to the HTTP part. HttpRequestBuilderheaders(Map<String, Object> values)Adds all the headers to the HTTP part. HttpRequestBuilderbody(String body)Sets the body of the HTTP part as a string value. HttpRequestBuilderbody(String body, String contentTypeString)Sets the body of the HTTP part as a string value. HttpRequestBuilderbody(ByteArray body)Sets the body of the HTTP part as a byte array. HttpRequestBuilderbody(ByteArray body, String contentTypeString)Sets the body of the HTTP part as a string value. HttpRequestBuilderbody(DslPart dslPart)Sets the body, content type and matching rules from a DslPart HttpRequestBuilderbody(BodyBuilder builder)Sets the body, content type and matching rules from a BodyBuilder HttpRequestBuilderbodyMatchingContentType(String contentType, ByteArray exampleContents)Sets up a content type matcher to match any body of the given content type HttpRequestBuilderbodyMatchingContentType(String contentType, String exampleContents)Sets up a content type matcher to match any body of the given content type HttpRequestBuilderqueryParameter(String key, Object value)Adds a query parameter to the request. HttpRequestBuilderqueryParameters(String key, String value, Array<out String> nameValuePairs)Adds all the query parameters to the request. HttpRequestBuilderqueryParameters(Array<out Pair<String, Object>> nameValuePairs)Adds all the query parameters to the request. HttpRequestBuilderqueryParameters(Map<String, Object> values)Adds all the query paraneters to the request. HttpRequestBuilderqueryParameters(String query)Adds all the query parameters to the request. -
-
Method Detail
-
build
final HttpRequest build()
Terminate the builder and return the request object
-
method
final HttpRequestBuilder method(String method)
HTTP Method for the request.
-
path
final HttpRequestBuilder path(String path)
Path for the request.
-
path
final HttpRequestBuilder path(Matcher matcher)
Sets the path of the request using a matching rule. For example:
path(regexp("\\/path\\/\\d+", "/path/1000"))
-
header
HttpRequestBuilder header(String key, Object value)
Adds a header to the HTTP part. The value will be converted to a string (using the toString() method), unless it is a List. With a List as the value, it will set up a multiple value header. If the value resolves to a single String, and the header key is for a header that has multiple values, the values will be split into a list.
For example:
header("OPTIONS", "GET, POST, PUT")is the same asheader("OPTIONS", List.of("GET", "POST, "PUT"))
-
headers
HttpRequestBuilder headers(String key, String value, String nameValuePairs)
Adds all the headers to the HTTP part. The values will be converted to a string (using the toString() method), and the header key is for a header that has multiple values, the values will be split into a list.
For example:
headers("OPTIONS", "GET, POST, PUT")is the same asheader("OPTIONS", List.of("GET", "POST, "PUT"))
-
headers
HttpRequestBuilder headers(Pair<String, Object> nameValuePairs)
Adds all the headers to the HTTP part. The values will be converted to a string (using the toString() method), and the header key is for a header that has multiple values, the values will be split into a list.
For example:
headers("OPTIONS", "GET, POST, PUT")is the same asheader("OPTIONS", List.of("GET", "POST, "PUT"))
-
headers
HttpRequestBuilder headers(Map<String, Object> values)
Adds all the headers to the HTTP part. You can either pass a Map<String -> String>, and values will be converted to a string (using the toString() method), and the header key is for a header that has multiple values, the values will be split into a list.
For example:
headers(Map<"OPTIONS", "GET, POST, PUT">)is the same asheader(Map<"OPTIONS", List<"GET", "POST, "PUT">>))Or pass in a Map<String -> List<String>> and no conversion will take place.
-
body
HttpRequestBuilder body(String body)
Sets the body of the HTTP part as a string value. If the content type is not already set, it will try to detect the content type from the given string, otherwise will default to text/plain.
-
body
HttpRequestBuilder body(String body, String contentTypeString)
Sets the body of the HTTP part as a string value. If the content type is not already set, it will try to detect the content type from the given string, otherwise will default to text/plain.
-
body
HttpRequestBuilder body(ByteArray body)
Sets the body of the HTTP part as a byte array. If the content type is not already set, will default to application/octet-stream.
-
body
HttpRequestBuilder body(ByteArray body, String contentTypeString)
Sets the body of the HTTP part as a string value. If the content type is not provided or already set, will default to application/octet-stream.
-
body
HttpRequestBuilder body(DslPart dslPart)
Sets the body, content type and matching rules from a DslPart
-
body
HttpRequestBuilder body(BodyBuilder builder)
Sets the body, content type and matching rules from a BodyBuilder
-
bodyMatchingContentType
HttpRequestBuilder bodyMatchingContentType(String contentType, ByteArray exampleContents)
Sets up a content type matcher to match any body of the given content type
-
bodyMatchingContentType
HttpRequestBuilder bodyMatchingContentType(String contentType, String exampleContents)
Sets up a content type matcher to match any body of the given content type
-
queryParameter
HttpRequestBuilder queryParameter(String key, Object value)
Adds a query parameter to the request. You can setup a multiple value query parameter by passing a List as the value.
-
queryParameters
HttpRequestBuilder queryParameters(String key, String value, Array<out String> nameValuePairs)
Adds all the query parameters to the request.
-
queryParameters
HttpRequestBuilder queryParameters(Array<out Pair<String, Object>> nameValuePairs)
Adds all the query parameters to the request.
-
queryParameters
HttpRequestBuilder queryParameters(Map<String, Object> values)
Adds all the query paraneters to the request. You can either pass a Map<String -> Object>, and values will be converted to a string (using the toString() method), or pass in a Map<String -> List<Object>> multi-value parameters.
-
queryParameters
HttpRequestBuilder queryParameters(String query)
Adds all the query parameters to the request.
-
-
-
-