-2

I have created a rest API service and code is running fine over the server.

I was wondering if there is a way through which we can send the python objects instead of the string, tuple, Response instance, or WSGI callable.

this python object contains the data inside them also.

Here is code for reference:

from flask import Flask , request , jsonify
import requests
app = Flask(__name__)

def fun(path1):
    data = ''
    with open(path1) as f:
        data = f.read()
    return data

@app.route('/client',methods=['POST'])
def client():
    data = request.get_json()
    path1 = data['loc']
    return fun(path1)

I was just wondering instead of data I should receive fun object. so that I can process in my local system in an application (pyqt) and do other task using this.

Note. what this question added by that these solve my query, I already did the problem using rest API by processing. what I am asking can I sent the object which I process on the server can be sent over rest API to my machine.

Note. what this question added by that these solve my query, I already did the problem using rest API by processing. what I am asking can I sent the object which I process on the server can be sent over rest API to my machine.

i am not asking for converting JSON to a python object. it is an object coming from processing various classes and function.

the flask is just used to run the server on the background. Django can be used here so added in the tag.

sahasrara62
  • 10,069
  • 3
  • 29
  • 44

2 Answers2

0

In REST usually use JSON format, for example(flask)

data = json.loads(request.data)
jsonify({'message': 'success'})
guest381
  • 155
  • 1
  • 2
  • 12
  • thanks for efforts, this is not what I am looking for. with JSON I have already done the solution. but i was wondering instead of processing that object in server process it in local system would be better for me , so asking is there a way to do that – sahasrara62 Apr 03 '19 at 11:18
0

You can serialize python objects pretty easily with pickle from Python Standard Library, making it harder to process for receiver (compared to JSON which is agnostic of processing language and human readable).

Kyryl Havrylenko
  • 674
  • 4
  • 11