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

Calling RestRequest.GetResourceUri(baseUrl) should be idempodent #70

Open
aaaabcv opened this issue Dec 21, 2019 · 0 comments · May be fixed by #71
Open

Calling RestRequest.GetResourceUri(baseUrl) should be idempodent #70

aaaabcv opened this issue Dec 21, 2019 · 0 comments · May be fixed by #71

Comments

@aaaabcv
Copy link

aaaabcv commented Dec 21, 2019

As the name "Get" implies, this method should not modify the request itself, or at least in an way which is idempodent.

Currently, the call adds the base URL and the query parameters to the Resource property, modifying it in the process. Calling it again, repeats the steps which leads to the base url added again as prefix and the query parameters as postfix.

While one could argue that a request is only meant to be used once and then thrown away, there are some reasons to call this information more than once:

  1. Logging of the Url will require it to be built before sending it. By calling this Get-method, actually sending the request will call it again and the request is unusable because of duplicate prefixes.
  2. Re-Authentication of failed requests: When e.g. Bearer Tokens expire it is a behaviour put between the actual API implementation and the REST Client which takes care about delegating the Authentication Challenge to an Identity Service, refreshing the Token, modify the Authentication Header and repeat the request transparent to the nature of the requests semantics. It would be convenient to modify the request and re-use it. This is currently not quite possible as for once, the request cannot be re-used as stated above and the original data (given by the Resource property) is modified so that base url of the RestClient and the QueryParameters are put in it so that the original Resource cannot be retrieved easily and put in a new request.

As solution and much better design attempt, please consider not modifying the public visible state during sending the request. Two possible attempts:

  1. Consider the request immutable after sending: Still the original data should be retrievable to build a second "equal" request from the first one
  2. Sending the request does not modify state of the request at all and allow reusing it.

In my opinion the second option would be the better as it provides more flexibility and has a more straight forward design without implicit states of the object.

@aaaabcv aaaabcv linked a pull request Dec 21, 2019 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant