GithubHelp home page GithubHelp logo

Remove object from every response about eel HOT 5 CLOSED

comcast avatar comcast commented on August 10, 2024
Remove object from every response

from eel.

Comments (5)

boriwo avatar boriwo commented on August 10, 2024

When you launch eel out of the box it will start listening for events on port 8080 using a default handler stored here https://github.com/Comcast/eel/blob/master/config-handlers/tenant1/default.json

The easiest thing to do would be to modify this default handler so it performs your transformation. You also need to adjust the endpoint you want to forward the transformed event to. Something like this should do:

{
    "Version": "1.0",
    "Name": "Default",
    "Info": "Default handler for everything. Doesn't apply any transformation and forwards everything unchanged to Endpoint/Path.",
    "Active": true,
    "Match": null,
    "IsMatchByExample": false,
    "TerminateOnMatch": true,
    "Transformation": {
        "{{/}}": "{{/items}}"
    },
    "IsTransformationByExample": false,
    "Path": "",
    "Verb": "POST",
    "Endpoint": "http://myproxytarget",
	"Protocol": "http",
    "HttpHeaders": {
      "X-B3-TraceId": "{{traceid()}}",
      "X-Tenant-Id": "{{tenant()}}"
    }
}

Hope this helps!

from eel.

g10chy avatar g10chy commented on August 10, 2024

Thanks Boris. Unfortunately this doesn’t help my required.

I need to:

Send GET request to eel and forward to target server as is.
Transform the JSON response from target server and pass onto the originating client.

Is this something eel can do?

from eel.

boriwo avatar boriwo commented on August 10, 2024

Yes, you can do this with eel as well. First of all you need to hit a different endpoint of eel: use /v1/sync/events to receive a synchronous response from eel rather than the default /v1/events which is used for event forwarding.

Next you might find the various built-in functions eel has useful. They are documented here:
https://github.com/Comcast/eel/blob/master/doc/functions.md

I put together an example for you based on your requirements using the functions curl(), eval() and prop(). I'm also using a custom properties section in the handler to manage the request against your service.

{
    "Version": "1.0",
    "Name": "Default",
    "Info": "Hit a remote service with the original payload and synchronously return a transformed response to original requestor.",
    "Active": true,
    "Match": null,
    "IsMatchByExample": false,
    "TerminateOnMatch": true,
    "Transformation": {
        "{{/}}": "{{eval('/items','{{prop('resp')}}')}}"
    },
    "CustomProperties" : {
        "resp" : "{{curl('GET', 'http://foo.com/bar', '{{/}}')}}"
    },
    "IsTransformationByExample": false,
    "Protocol": "null",
    "HttpHeaders": {
      "X-B3-TraceId": "{{traceid()}}",
      "X-Tenant-Id": "{{tenant()}}"
    }
}

Give this handler a try. You will probably have to fine tune it a little.

from eel.

g10chy avatar g10chy commented on August 10, 2024

Thanks for the pointers Boris.
I have configured as suggested above and it is working perfectly with POST to http://localhost:8080/v1/sync/events

However, my original requester can only issue GET (limitation in the application). But when I try using GET to get the response I have the following:

Browser output is:
{"error":"http post required","tx.traceId":"e47ead52-b2a9-40c1-8b11-2a4c10a2507e"}

Console output is:
{"action":"rejected","app.id":"eel","cause":"http_post_required","env.name":"default","error":"post required","error_type":"rejected","instance.id":"xxxxxxx","log.id":"e47ead52-b2a9-40c1-8b11-2a4c10a2507e","log.level":"error","log.timestamp":"2019-07-23T08:41:08.577866555Z","method":"GET","status":"400","tx.traceId":"e47ead52-b2a9-40c1-8b11-2a4c10a2507e"}

It is possible for eel to accept GET?

from eel.

boriwo avatar boriwo commented on August 10, 2024

Interesting. Before I was still assuming that your original request was posting a payload you wish to forward to your target service. If this is not the case and you simply want to kick this off with a payload-free GET request you are out of luck. EEL is designed to work around an incoming http POST and a (possibly empty) payload that is sent along with it.

from eel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.