Skip to content

Allow overriding Content-Type per OpenAPI operation #1336

@nasoooor29

Description

@nasoooor29

Describe the feature

Feature Request:

orpc currently always uses application/json as the Content-Type for OpenAPILink and other generated links (not sure). While this works for most cases, some APIs require different content types such as:

  • application/x-www-form-urlencoded
  • multipart/form-data

When using these content types, the request payload must be encoded differently than JSON.

Problem

There is no way to override Content-Type per operation, which prevents calling endpoints that do not accept JSON request bodies.

Expected Behavior

  • Allow overriding Content-Type per OpenAPI operation or link.
  • Automatically serialize request data based on the selected content type.

Examples (JavaScript)

application/json

fetch("/login", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    username: "help",
    password: "help",
  }),
})

application/x-www-form-urlencoded

fetch("/login", {
  method: "POST",
  headers: {
    "Content-Type": "application/x-www-form-urlencoded",
  },
  body: new URLSearchParams({
    username: "help",
    password: "help",
  }),
})

multipart/form-data

const form = new FormData()
form.append("username", "help")
form.append("password", "help")

fetch("/login", {
  method: "POST",
  body: form,
})

Use Case

Required for authentication endpoints, legacy APIs, and form-based submissions that do not accept JSON payloads.

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions