Skip to content

Add Link#_query to send undeclared query parameters - #334

Merged
dblock merged 1 commit into
codegram:masterfrom
dblock:dblock/link-query
Nov 21, 2026
Merged

dblock merged 1 commit into
codegram:masterfrom
dblock:dblock/link-query

Conversation

@dblock

@dblock dblock commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

HAL templated links only expand the variables they declare, and _expand drops anything else (as documented in the README). That left no way to send extra query parameters, such as a sort the API accepts but doesn't declare, or any parameters on a link that isn't templated (#84).

This adds Link#_query(params), which returns a new link with the parameters appended to its URL:

api._links.places._query(sort: 'name')._get # GET /places/?sort=name
api._links.place._expand(id: 'oxpoints:23232339')._query(fields: 'name')._get # GET /places/oxpoints%3A23232339?fields=name
  • Works on templated and non-templated links, and survives _expand in either order.
  • Appends to the existing query string and keeps the fragment, so repeated keys already in the href are preserved (it doesn't round-trip through Addressable::URI#query_values, which drops repeated keys and sorts).
  • Array values become repeated parameters, matching the FlatParamsEncoder used by the connection; nil values are dropped, like undefined template variables.
  • _expand stays strict, so existing behavior is unchanged.

This supersedes #92 (2015), which patched URITemplate to expand undeclared variables by default; Hyperclient has since moved to Addressable and that patch no longer applies.

Closes #84.

Validation

  • bundle exec rake on Ruby 4.0.9: Minitest 171 runs, 0 failures; Spinach 32 steps passed; RuboCop 34 files, no offenses.
  • The 9 new _query tests fail against master's link.rb and pass with this change.
  • Ran both README snippets against the local Oxford demo (examples/oxford/server.rb); the server logged GET /places/?sort=name and GET /places/oxpoints%3A23232339?fields=name.

This PR was written by an AI (Claude) acting on behalf of @dblock.

🤖 Generated with Claude Code

https://claude.ai/code/session_011Gr21mVM7TZeZyebArnTs9

HAL templated links only expand the variables they declare, so callers had
no way to send extra query parameters, or any parameters on a link that is
not templated. `_query(params)` returns a new link with the parameters
appended to its URL after any existing query string, keeps them across
`_expand`, repeats array values and drops nil values. `_expand` stays
strict.

Closes codegram#84.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Gr21mVM7TZeZyebArnTs9
@github-actions

Copy link
Copy Markdown
Contributor

Danger Report

No issues found.

View run

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 99.694% (+0.007%) from 99.687% — dblock:dblock/link-query into codegram:master

@dblock
dblock merged commit b170961 into codegram:master Nov 21, 2026
11 checks passed
@dblock
dblock deleted the dblock/link-query branch November 21, 2026 20:55
@dblock dblock mentioned this pull request Nov 21, 2026
dblock added a commit that referenced this pull request Nov 21, 2026
Link#_query (#334) is a backward-compatible feature, so the next release is
a minor version. Move the changelog placeholder below the entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Gr21mVM7TZeZyebArnTs9
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.

Dynamic path with GET request

2 participants