Skip to content

Add ETag Support to HackMD API Client #31

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

bagnier
Copy link

@bagnier bagnier commented Mar 30, 2025

Add ETag Support to HackMD API Client

Summary

This PR implements ETag support for HackMD API client operations, enabling conditional requests and response caching.

Technical Details

  • Added ETag support to GET, POST, and PATCH operations for user notes
  • ETags are now accessible in responses for getNote, createNote, updateNote, and updateNoteContent
  • Implemented proper handling of 304 Not Modified responses for conditional GET requests

Limitations

  • The HackMD API server does not currently support If-Match headers in PATCH requests, limiting conditional updates
  • Current implementation focuses on user notes operations - the most commonly used endpoints.

Implementation Approach

  • Made ETag usage optional to preserve backward compatibility
  • Included ETags automatically in responses when available
  • Required explicit opt-in for conditional requests via the options parameter
  • Focused implementation on user notes operations only (not team notes)
  • Comprehensive test suite verifies all ETag functionality scenarios

Security

  • Updated dependencies to fix vulnerabilities

bagnier added 4 commits March 28, 2025 20:32
      - Remove test.only to run all tests
      - Create dedicated client instance with retry disabled for rate limit tests
      - Fix Jest exit issues with proper cleanup
      - Remove debug console.log statements
  - Update axios from 0.25.0 to 1.8.4
  - Update msw from 1.0.1 to 2.7.3
  - Refactor mock server implementation to use MSW v2 API
  - Update API client to use new axios types
  - Fix type issues in headers handling
  - Add etag field to RequestOptions type
  - Implement conditional requests with If-None-Match header
  - Add proper handling of 304 Not Modified responses
  - Extract etag from response headers
  - Include etag in response data when requested
  - Add comprehensive test coverage for etag functionality
  * Add etag support to createNote method
  * Add etag support to updateNoteContent method
  * Add etag support to updateNote method
  * Organize tests by API method
  * Improve test naming for clarity
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.

1 participant