Skip to content

Conversation

Edgar0bsj
Copy link

Pull Request Description

This pull request adds native support for the MIME type application/json-patch+json to Restify’s core body parsers. This enables proper parsing of HTTP PATCH requests that use JSON Patch documents, without relying on external middleware or regex fallbacks.

Changes Made

File: lib/plugins/bodyParser.js
Modification:
Added a new case to the MIME type switch in the parseBody function:

case 'application/json-patch+json':
    parser = parseJson[0];
    break;

Impact:
Ensures that requests with Content-Type: application/json-patch+json are parsed using the standard JSON parser.


File: lib/plugins/jsonBodyParser.js
Modification:
Extended the MIME type check in the parseJson function to explicitly include application/json-patch+json:

if (
    !req.body ||
    (
        contentType !== 'application/json' &&
        contentType !== 'application/json-patch+json' &&
        !regex.jsonContentType.test(contentType)
    )
) {
    return next();
}

Impact:
Guarantees that the JSON parser is triggered for requests using the JSON Patch MIME type, even when the content type includes charset parameters.

Expected Behavior

  • Requests with Content-Type: application/json-patch+json are parsed as JSON.
  • req.body will contain a valid array of JSON Patch operations.
  • No side effects or regressions for existing MIME types.

Manual Testing

  • Sent a PATCH request using Postman with Content-Type: application/json-patch+json
  • Verified that req.body was correctly parsed as a JSON array
  • Confirmed that the server responded with 204 No Content and no parsing errors

Consideration

This implementation was intentionally scoped to be minimal and non-invasive, aiming to integrate support for JSON Patch with the least possible impact on existing parsing logic or behavior. The changes are isolated, additive, and follow the established structure of Restify’s core.

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