mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-26 01:06:00 +03:00
[PR #5244] [MERGED] feat(kernel): extensible content media types #5124
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#5124
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/5244
Author: @CuriousCorrelation
Created: 7/15/2025
Status: ✅ Merged
Merged: 7/24/2025
Merged by: @jamesgeorge007
Base:
next← Head:feat-kernel-extensible-content-media-types📝 Commits (2)
fe7a1e3feat(kernel): extensible content media types1c52a06docs(kernel): exec guarantees ofexampleobject📊 Changes
2 files changed (+174 additions, -25 deletions)
View changed files
📝
packages/hoppscotch-common/src/helpers/kernel/common/content.ts(+49 -6)📝
packages/hoppscotch-kernel/src/relay/v/1.ts(+125 -19)📄 Description
This makes content transformation system extensible by allowing custom media types alongside the predefined
MediaTypeenum values and clarifies the distinction between content routing and HTTP headers.Closes FE-910
The
kindfield controls content processing routing. Web mode with Axios completely ignoreskindand relies on auto-detection. Desktop mode with relay useskindto route to specificrelayfunctions likeset_json_content(),set_form_content(),set_binary_content()in the content handler. ThemediaTypefield sets the HTTP Content-Type header in both environments regardless of which processing route is taken.The content transformation system was too restrictive, only accepting specific
MediaTypeenum values instead of flexible vendor-specific formats. More importantly tho, this clarifies fundamental distinction betweenkindandmediaTypefields and their different purposes.What's change
Updated all
ContentTypevariant definitions to acceptMediaType | stringinstead of restrictive enum unions. MademediaTypeparameter optional in all content factory functions with sensible defaults. Added documentation explaining the routing vs header distinction and processor behavior for each content type.Removed
parseJSONAs<unknown>(body)validation from theJSONprocessor. The JSON processor now treats input as pre-stringified JSON text without validation, since validation belongs in upper layers, not the processor layer. Binary processor explains Blob toUint8Arrayconversion with filename preservation. Form processors clarify URL-encoded vs multipart handling. Added examples section showing both new capabilities and backward compatibility patterns.Implementation
The changes preserve full backward compatibility. Web mode with Axios ignores the kind field and relies on auto-detection, desktop mode with relay uses kind to route to specific processing fn(s). The mediaType field always sets the HTTP Content-Type header in both environments.
Custom formats now work. Vendor-specific JSON uses content.json({ data: { type: "users" } }, "application/vnd.api+json"). Pre-stringified JSON can be sent without encoding with content.text('{"escaped": "content"}', MediaType.APPLICATION_JSON). Custom XML schemas work with content.xml('soap:Envelope...</soap:Envelope>',
"application/soap+xml").
Notes to reviewers
This change affects both type definitions and some functional behavior but maintains backward compatibility for existing valid usage patterns.
All existing code continues to work exactly as before, but now supports custom media types with clearer understanding of the content system's design principles.
Testing should verify that existing content creation continues to work and new custom media types are accepted by the type system.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.