Giter Club home page Giter Club logo

Comments (9)

aemonge avatar aemonge commented on August 15, 2024

Never mind, i've read this and answered my self
http://greim.github.io/hoxy/#request-json

from hoxy.

aemonge avatar aemonge commented on August 15, 2024

Okey !!!
I've seen that the .JSON only works with 'request' phase. So how could I respond selectively different data based on a condition that uses the body (req.json) ?

from hoxy.

aemonge avatar aemonge commented on August 15, 2024

Yup, I've edited the title so it's more accurate.

from hoxy.

greim avatar greim commented on August 15, 2024

If I understand the question, you'd just use if (req.json.something...) somewhere in the intercept handler.

from hoxy.

aemonge avatar aemonge commented on August 15, 2024

Because I need the servers answer. I'm trying:
a) to extend servers API. For example, if req.json.extend === true then _.assign(resp.json, { more: true })
so i can finally ) When incoming request, answer a stored (in mongo) version of it ( aka cached ), then continue the request so I can update that stored value with the newest server response

_.assign is the new alias for old _.extend in lodash.

from hoxy.

aemonge avatar aemonge commented on August 15, 2024
proxy.intercept({
  phase: 'request',
  as: 'json'
}, function(req, resp) {
  var a;
  var requestHash = {
    url: req.url,
    method: req.method,
    headers: req.headers,
    body: req.json
  };
  _.assign(resp.json, {extende: true}); // <- Response isn't being extende, on this phase
  console.log('Check for JSON -> ', req.json.nickname);
  console.log('Respond default extende ->', resp.json);
});

proxy.intercept({
  phase: 'response',
  as: 'json'
}, function(req, resp) {
  var a;
  var requestHash = {
    url: req.url,
    method: req.method,
    headers: req.headers,
    body: req.json
  };
  // _.assign(resp.json, {extende: true}); // <- Response here does extends here, but I've got undefined on req.json
  console.log('Store the value of original -> ', req.json.nickname);
  console.log('With this data, not extended', resp.json);
});

from hoxy.

greim avatar greim commented on August 15, 2024

You could assign response.json = { ... } during the request phase, but be warned it will suppress the call to the server. http://greim.github.io/hoxy/#response-population

If that isn't what you want, check out this: http://greim.github.io/hoxy/#cycle-data

It would allow you to pass a value from the request to the response cycle which should get you where you need.

from hoxy.

aemonge avatar aemonge commented on August 15, 2024

Thanks !! I'll give it a try, and tell you later ;)

from hoxy.

aemonge avatar aemonge commented on August 15, 2024

That did the trick !!! Thanks a lot !!!!

from hoxy.

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.