wiremock-testcontainers-java icon indicating copy to clipboard operation
wiremock-testcontainers-java copied to clipboard

Idea: Unify methods to get endpoint url

Open bitxon opened this issue 2 years ago • 1 comments

Proposal

Goal is to simplify public interface of the WireMockContainer class

Current methods

public String getEndpoint() {
  return String.format("http://%s:%d", getHost(), getMappedPort(PORT));
}
public URI getRequestURI(String relativePath) throws URISyntaxException {
  return new URI(getEndpoint() + "/" + relativePath);
}

Option 1

Align method names with WireMockServer class

public String baseUrl() {
  return String.format("http://%s:%d", getHost(), getMappedPort(PORT));
}
public String url(String path) {
  if (!path.startsWith("/")) {
    path = "/" + path;
  }
  return baseUrl() + path;
}

Motivation

  1. Simplify switch from Embedded wiremock to Testcontainer
  2. Familiar api for developers

Option 2

  public String getEndpoint() {
    return String.format("http://%s:%d", getHost(), getMappedPort(PORT));
  }
  public String getEndpoint(String path) {
    if (!path.startsWith("/")) {
      path = "/" + path;
    }
    return getEndpoint() + path
  }

Motivation

  1. Use Overloaded methods getEndpoint
    • naming consistency
    • easier for developer to memorize and intuitively understand what method does
  2. Allow path to be with / and without it
  • simplify switch from WireMockServer to WireMockTestcontainer

References

No response

bitxon avatar May 02 '23 19:05 bitxon

+1 for alignment of the methods, or maybe even having a shared interface in the [far] future

oleg-nenashev avatar May 05 '23 20:05 oleg-nenashev