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

Better separation of concerns when making requests. #260

Closed
wants to merge 9 commits into from

Conversation

rudolfbyker
Copy link
Collaborator

(Note that this builds upon #259 and #258 so we should merge those first.)

Previously, we had .get and .post, which did something like this:

get:

  • Build a query.
  • If the URL is too large, throw everything away and call post.
  • Perform HTTP GET.

post:

  • Build a query.
  • Perform HTTP POST.

The problem with this is that neither GET nor POST what one would expect. Neither are general HTTP GET or POST utilities. They work specifically with Solr Query objects. They expect JSON responses only. They send their data as query strings only (even .post, which uses application/x-www-form-urlencoded).

Therefore this can be much better encapsulated as:

doQuery:

  • Take a Solr Query object, and prepare data for an HTTP query from that.
  • Decide whether GET or POST should be used (note that this behaviour comes from Search Solr using POST instead of GET #129 – I did not invent it)
  • Call doRequest.

doRequest:

  • Build the query.
  • Send the query.

This maintains a single level of abstraction per method, and therefore gives better separation of concerns and results in more understandable code. Se http://www.principles-wiki.net/principles:single_level_of_abstraction

@rudolfbyker
Copy link
Collaborator Author

Re-doing this.

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 this pull request may close these issues.

None yet

1 participant