Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace factory with builder when creating operation requests/responses #886

Open
AugustoRavazoli opened this issue Apr 9, 2023 · 1 comment

Comments

@AugustoRavazoli
Copy link

Both the OperationRequestFactory and OperationResponseFactory leads to unnecessary code in custom pre-processors:

new OperationRequestFactory().create(
  uri,
  request.getMethod(),
  request.getContent(),
  headers,
  request.getParts(),
  cookies
);

A possible way to simplify the request creation is to use the Builder design pattern:

new OperationRequestBuider(request)
  .withUri(uri)
  .withHeaders(headers)
  .withCookies(cookies)
  .build();

The OperationRequestBuilder will builds the new request using the request argument fields as defaults, like a StringBuilder.

AugustoRavazoli added a commit to AugustoRavazoli/spring-restdocs that referenced this issue Apr 29, 2023
…uests and responses

The intent of this change is to provide a better api to work with, dispensing repeated code from the factories

Fixes spring-projectsgh-886
@wilkinsona
Copy link
Member

While this is quite a low-level API that many people won't touch, I can see the value in making it more concise and easier to use. Before doing so, I'd like the outcome of #733 to be decided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants