james-proxy / james

Web Debugging Proxy Application
1.42k stars 125 forks source link

Add map url to merge #416

Closed adsonpleal closed 3 years ago

adsonpleal commented 4 years ago

Motivation

I needed a way to only map specific parts of a request response leaving the rest untouched.

New dependencies

deepmerge: used to perform object deep merge react-json-view: used to pretty print, collapse and edit JSON.

Changes

Added functionality to add a "url to merge" mapping. Now is possible to map a url to a deep merge JSON.

Let's say that we have a request that returns:

{
    "a": 1,
    "b": {
        "c": 2,
        "d": 3
    }
}

And we want to merge it with:

{
    "b": {
        "d": 4
    }
}

The result will be:

{
    "a": 1,
    "b": {
        "c": 2,
        "d": 4
    }
}

For arrays it will fully replace the array:

Request:

{
    "a": 1,
    "b": {
        "c": [ 1, 3, 4 ], 
        "d": 3
    }
}

Merge:

{
    "b": {
        "c": [ 3, 4, 5 ]
    }
}

Result:

{
    "a": 1,
    "b": {
        "c": [ 3, 4, 5 ], 
        "d": 3
    }
}

Screenshots:

New "URL TO MERGE" button. Screen Shot 2020-01-14 at 10 15 42 AM

New "Edit mapping button" (only for "merge" mappings).

Screen Shot 2020-01-14 at 10 16 21 AM

New "Edit mapping" screen:

Screen Shot 2020-01-14 at 10 17 28 AM Screen Shot 2020-01-14 at 10 17 36 AM

mitchhentges commented 4 years ago

Hey, thanks for the pull request!

Heads up that James isn't being updated these days. Thank you for providing these changes upstream, but since we probably won't be doing another release, I won't land them. However, we should leave this PR here so that another developer forks James, they can land your changes in their repo :smile: