Skip to content

Add protected ability to request JSON results with token#353

Merged
matt-bernhardt merged 1 commit intomainfrom
rest-api
Feb 19, 2026
Merged

Add protected ability to request JSON results with token#353
matt-bernhardt merged 1 commit intomainfrom
rest-api

Conversation

@JPrevost
Copy link
Member

@JPrevost JPrevost commented Jan 30, 2026

This adds a JSON interface for Unified Search results, which is necessary for Quepid to communicate with the application. There may also be other consuming applications, so we are trying not to couple this work too tightly with Quepid.

In order to protect access to this new formatting option, we also define a before_action check, comparing an agent-provided token against a value stored in a new env variable. If the values match, the check passes and the request can be processed. We do this in the before_action step, because if the values don't match there's no reason to do any work in response to the request.

The review app for this PR has been added as a search option within our Quepid instance, and there's a 1-term case defined that is showing that results are received. If you want to confirm that side of things, let me know and I'll create a user account for you.

Developer

Ticket: https://mitlibraries.atlassian.net/browse/USE-400

Accessibility
  • ANDI or WAVE has been run in accordance to our guide.
  • This PR contains no changes to the view layer.
  • New issues flagged by ANDI or WAVE have been resolved.
  • New issues flagged by ANDI or WAVE have been ticketed (link in the Pull Request details above).
  • No new accessibility issues have been flagged.
New ENV
  • All new ENV is documented in README.
  • All new ENV has been added to Heroku Pipeline, Staging and Prod.
  • ENV has not changed.
Approval beyond code review
  • UXWS/stakeholder approval has been confirmed.
  • UXWS/stakeholder review will be completed retroactively.
  • UXWS/stakeholder review is not needed.
Additional context needed to review

E.g., if the PR includes updated dependencies and/or data
migration, or how to confirm the feature is working.

Code Reviewer

Code
  • I have confirmed that the code works as intended.
  • Any CodeClimate issues have been fixed or confirmed as
    added technical debt.
Documentation
  • The commit message is clear and follows our guidelines
    (not just this pull request message).
  • The documentation has been updated or is unnecessary.
  • New dependencies are appropriate or there were no changes.
Testing
  • There are appropriate tests covering any new functionality.
  • No additional test coverage is required.

@coveralls
Copy link

coveralls commented Jan 30, 2026

Pull Request Test Coverage Report for Build 22199215526

Details

  • 12 of 12 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 98.14%

Totals Coverage Status
Change from base Build 21953938306: 0.02%
Covered Lines: 1319
Relevant Lines: 1344

💛 - Coveralls

@mitlib mitlib temporarily deployed to timdex-ui-pi-rest-api-imfbdly0 January 30, 2026 18:35 Inactive
@JPrevost JPrevost temporarily deployed to timdex-ui-pi-rest-api-imfbdly0 January 30, 2026 18:50 Inactive
@mitlib mitlib temporarily deployed to timdex-ui-pi-rest-api-tb3mnmuu February 4, 2026 21:01 Inactive
@mitlib mitlib temporarily deployed to timdex-ui-pi-rest-api-k9sfocpz February 12, 2026 16:25 Inactive
@matt-bernhardt matt-bernhardt force-pushed the rest-api branch 2 times, most recently from c276758 to 1d93a19 Compare February 19, 2026 17:21
@mitlib mitlib temporarily deployed to timdex-ui-pi-rest-api-rf1ta92y February 19, 2026 18:30 Inactive
@matt-bernhardt matt-bernhardt changed the title Experimental JSON format for unified results Add protected ability to request JSON results with token Feb 19, 2026
@JPrevost JPrevost self-assigned this Feb 19, 2026
Copy link
Member Author

@JPrevost JPrevost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, I can't approve because I opened this initially.

@matt-bernhardt I approve this PR as-is. Feel free to approve it yourself (I think you should be able to) and then merge :shipit:

** Why are these changes being introduced:

The application we are implementing to measure result relevance needs a
JSON endpoint for getting search results.

** Relevant ticket(s):

* https://mitlibraries.atlassian.net/browse/use-400

** How does this address that need:

This adds an ability to serve search results in JSON format, leveraging
Rails' built-in respond_to block.

In order to make sure that we control access to this endpoint, we also
add a before_action check to make sure that a requesting user agent
supplies a token that matches a newly-created environment variable.

If that environment variable is not set, or the received token does not
match, the request for JSON formatted results will be denied with a 401
Unauthorized status.

** Document any side effects to this change:

None, hopefully. We use the before_action check to prevent unnecessary
resource use or computation, so hopefully that will help prevent our
wasting energy on invalid requests.
@mitlib mitlib temporarily deployed to timdex-ui-pi-rest-api-rf1ta92y February 19, 2026 20:39 Inactive
Copy link
Member

@matt-bernhardt matt-bernhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving this after seeing the feedback from @JPrevost

@matt-bernhardt matt-bernhardt merged commit adb21fa into main Feb 19, 2026
5 checks passed
@matt-bernhardt matt-bernhardt deleted the rest-api branch February 19, 2026 20:42
Copy link
Contributor

@jazairi jazairi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registering another approval, just for good measure. 🙂

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.

5 participants

Comments