Add HTTP caching, JSON-only routes, 404 handling, and OpenAPI spec#77
Open
Add HTTP caching, JSON-only routes, 404 handling, and OpenAPI spec#77
Conversation
…spec - Routes: wrap all endpoints in `defaults format: :json` — no .json suffix needed - ApplicationController: rescue RecordNotFound with JSON 404 response; add `cache_and_validate` helper that sets Cache-Control and calls `fresh_when` for ETag/Last-Modified conditional GET support (304 Not Modified) - Books/Chapters controllers: call `cache_and_validate` on every action - doc/openapi.yaml: full OpenAPI 3.0 spec documenting all 6 endpoints with caching headers, conditional request parameters, and all response schemas Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Fix Rubocop: use hash-rocket syntax throughout (project convention) - Rename cache_and_validate → set_cache (avoid confusion with AR validations) - Pass public: true to fresh_when explicitly rather than relying on the pre-set Cache-Control header being detected - content action: use composite ETag/Last-Modified covering tuks and pauri_translations so edits to nested content invalidate client caches Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Gemfile: move csv before rack-cors (alphabetical order) - Migration: rubocop:disable ThreeStateBooleanColumn (old migration, can't change) - spec/rails_helper.rb: use Rails.root.glob instead of Dir[Rails.root.join] - spec/models/chapter_spec.rb: rename book1/book2 to first_book/second_book - spec/services/granth_importer_spec.rb: rename tuk1/tuk2 to first_tuk/second_tuk Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This reverts commit 8c20caa.
These violations existed on main since before this PR. Suppressing them via rubocop_todo.yml rather than touching unrelated files. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
defaults format: :json— clients no longer need.jsonsuffixcache_and_validatehelper inApplicationControllersetsCache-Control: public, max-age=3600, stale-while-revalidate=60and wires up ETags +Last-Modifiedvia Rails'fresh_when— repeat requests return304 Not Modifiedwhen data hasn't changedrescue_from ActiveRecord::RecordNotFoundnow returns a JSON error body{ "error": "Not found" }with HTTP 404 instead of an HTML pagedoc/openapi.yaml— full OpenAPI 3.0 spec documenting all 6 endpoints, response schemas, caching headers, and conditional request parametersTest plan
GET /booksreturns JSON without.jsonsuffixGET /books/9999returns{"error":"Not found"}with status 404GET /bookswithIf-None-Match: <etag from first response>returns 304doc/openapi.yamlwith Swagger Editor🤖 Generated with Claude Code