Skip to content

How would one receive a json object, process it, then return Json back via http in asp.vNext? #787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
govpack opened this issue Jul 31, 2015 · 4 comments

Comments

@govpack
Copy link

govpack commented Jul 31, 2015

How would one receive a json object +[process with a dynamically loaded method /async task]
and then return the Json result back via http in asp.vNext?

It's a pretty common use case for an http server to be able to act as a json API... last night i cloned and browsed the source code of glimpse v2, to see how such a thing could be done (but there were way too many files and i didn't know which way was up) i google and i bing but i'm yet to see a small example that demonstrates such a thing in action.

for example here's how it could be done in 50 lines of javascript using dynamically loaded worker methods in •r:Ruby •v:JS •w:Clojure •x:Perl •y:Python •z:PHP

vx=require('vertx')
LOG=require('vertx/console').log
container=require('vertx/container')
DP=container.deployWorkerVerticle
l={a:LOG,j:JSON.stringify}
eb=vx.eventBus;
eb.registerHandler('godo',godo)
NUT={}
toolz={
fix:function(o){/*Ready o.[rx|rv|ry|rn] properties*/
if(typeof o.rx=='number'){o.rx=[o.rx.toString()]}
if(typeof o.rx=='string'){o.rx=o.rx.replace(/[\W\s]+$/,'').split('/');for(var i=0;i<o.rx.length;i++){if(/^-?\d+/.test(o.rx[i])){o.rx[i]=Number(o.rx[i])}}}
if(typeof o.rv=='undefined'){o.rv=''}
if(typeof o.ry=='undefined'){o.ry=[]}
if(typeof o.rn=='undefined'){o.rn=0}
if(o.cb){/*jsonp*/o.rb=-3}
if((''+o.rx[0]).charAt(0)=='~'){o.rb='-'+o.rx[0].substr(1);o.rx.shift()}else if(!o.rb){o.rb=o.all?-2:-1}
}
}
var N=0

function godo(o,cb){/*Run o thru one or more verticles*/
LOG(o.rn+' von.js received: ' + l.j(o));o.rb=++N
NUT[o.rb]=(function(cb){return function(o){cb(o)}})(cb)
toolz.fix(o)
DoNext(o)
} 

function DoNext(o){LOG(o.rn)
if(o.rn!=0){o.e=o.rv}
if(o.rn>=o.rx.length){LOG('returning: ' + l.j(o));NUT[o.rb](o);/*delete NUT[o.rb]*/;return}
var ns=''+o.rx[o.rn];var s=ns.charAt(0);var n=parseInt(ns.substr(1))
LOG(o.rn+'/'+o.rx.length+' ~ '+ns+'['+n+']'+s)
o.rn+=1;
var ext=({r:'rb',v:'js',w:'clj',x:'pl',y:'py',z:'php'})[s]
LOG('EXT:'+ext)
if(!ext){NUT[o.rb](o);delete NUT[o.rb];return}
if(s=='v' && n==3){var RV='fail';try{eval('RV=('+o.e+')')}catch(er){RV=er.message};LOG(RV);o.rv=RV;return DoNext(o);}
if(NUT[ns]){LOG(ns+' already loaded');return eb.send(ns,o,DoNext)}
var fpr='../../../../2/'+s+s+'/Ax/'+n+'/'+s+'.'+ext;LOG('ns:'+ns);LOG('ns:'+fpr)
container.deployVerticle(fpr,null,1,function(){NUT[ns]=true;eb.send(ns,o,DoNext)})
}

web1=vx.createHttpServer()
sox=vx.createSockJSServer(web1)
sox.bridge({prefix:'/eventbus'},[{}],[{}])
web1.listen(1422)

this is the same question as: #770
except that one shows "Powershell Listening on http://127.0.0.1:1416..."
getting and returning Json via http

@Eilon
Copy link
Member

Eilon commented Jul 31, 2015

@danroth27

@aspnet-hello
Copy link

This issue is being closed because it has not been updated in 3 months.

We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate.

@davidalpert
Copy link

davidalpert commented Dec 31, 2017 via email

@davidalpert
Copy link

davidalpert commented Dec 31, 2017 via email

natemcmaster pushed a commit that referenced this issue Nov 20, 2018
SteveSandersonMS added a commit that referenced this issue Nov 27, 2018
* Simple autorebuild mechanism for hosted apps

* CR feedback: DI changes; use Directory.EnumerateFiles

* CR feedback: Ensure FileSystemWatcher isn't GCed
dougbu pushed a commit to dotnet-maestro-bot/AspNetCore that referenced this issue Sep 11, 2019
Copy scafolding NugetPackageVerifier rules from the repo
@ghost ghost locked as resolved and limited conversation to collaborators Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants