Skip to content
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

Hello http+json->object->load[method]-call[method+object]->stringify[object]->goodbye json->http #818

Closed
govpack opened this issue Aug 11, 2015 · 3 comments

Comments

@govpack
Copy link

govpack commented Aug 11, 2015

hi,
how's it all going?
i was wondering how the following can be done using asp .NET 5?

  1. Hello http
  2. Hello json
  3. Hello dynamic object (are inferred classes possible from json? or do i need to provide a generic one?)
  4. Hello dynamically loaded method -- retrieved from memory||disc||dll||cs
  5. asyncMethod(object) --> result
  6. ReturnViaHttp(JSON.stringify(result)) // goodbye json

any links/docs/samples that could
help me implement this would be great

thanks

i don't know or particularly like python, but i'm working thru the various languages, and doing the same task (as above) it took me half a day to write the following in python, and in powershell ~ #770 and vert.x #787 these three posts are all the same issue just stated in different ways

http+json->object->load[method]-call[method+object]->stringify[object]->goodbye json->http

import json
import urllib
import cgi
import time
from os import curdir
from os.path import join as pjoin
from importlib import import_module
from http.server import BaseHTTPRequestHandler, HTTPServer
import imp
import urllib.request
import sys
hd=__file__.replace("2/1/Ax/250/run.py","")

NUT={}


def getf(rx):
    if rx in NUT.keys():return NUT[rx]
    mod = imp.load_source('bar',hd+'2/yy/Ax/'+(rx[1:])+'/y.py')
    NUT[rx]=mod.task
    return NUT[rx]

def next(o):
    rn=o.get('rn',-1)
    rn+=1
    o['rn']=rn
    if rn>0:o['e']=o.get('rv','')
    print('####'+str(rn))
    if type(o.get('rx')) is not list: return o
    RX=o.get('rx')
    if rn>=len(RX):return o
    try:rx=RX[rn]
    except Exception:return o


    if rx:
        if rx[0]!='y':return o

        f=getf(rx)
        f(o)
        return next(o)
    return o




class web1(BaseHTTPRequestHandler):
    def do_GET(self):
            self.request.sendall((json.dumps({'path':self.path,'d':int(time.time()*1000),'a':1,'b':2,'c':[1,2,3]}).encode("utf-8")))
    def do_POST(self):
        try:
            if 'content-length' in self.headers:
                length= int(self.headers['content-length'])
                data = self.rfile.read(length).decode("utf-8")
                o2 = json.loads(data)
                rc=o2.get('rc',0)
                if rc:
                    self.request.sendall(json.dumps(o2).encode("utf-8"));
                    pass
                rx=o2.get('rx',0)
                if rx:
                    next(o2)
                    self.request.sendall(json.dumps(o2).encode("utf-8"));
                    pass
            else:
                print("No data")
                self.send_response(200)
                self.send_header("Content-Type", "text/json; charset=UTF-8")
                self.end_headers();
                self.wfile.write("No data");
        except Exception as excp:
            print(excp)
            self.send_response(200)
            self.send_header("Content-Type", "text/json; charset=UTF-8")
            self.end_headers();
            self.wfile.write(str(excp));



http = HTTPServer(('localhost',1425), web1)
print('Python listening on http://127.0.0.1:1425/ \n'+sys.version)
http.serve_forever()
@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

@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

3 participants