How to catch the query string from a Restful request

0

I need to get the parameters passed by the URI, for example:

http://localhost/endpoint/param1/param2/param3
if param1 == "adduser"
    id = param2
    name = param3

Example of a function that did not work: I'm looking for a way to search !!!

from flask import Flask
from flask_restful import Resource, Api, reqparse

app = Flask(__name__)
api = Api(app)

class HelloWorld(Resource):
    def post(self):
        myargs = {}
        for field in ("id","nome"):
            myargs[field] = request.form.get(field)

        print(myargs["id"].decode("utf-8"))
        print(myargs["nome"].decode("utf-8"))

api.add_resource(HelloWorld, '/teste')

if __name__ == '__main__':
    app.run(debug=True) 
    
asked by anonymous 24.02.2017 / 19:55

1 answer

0

I would like to record how we have overcome this difficulty.

We developed a routine in Python + Flask

from flask import Flask
from flask import request

from api import create_user, get_sso

app = Flask(__name__)

@app.route("/users")
def users():
    data = request.args.to_dict()
    response = create_user(**data)
    if response.status_code == 200:
        return "OK"
    else:
        return response.content

This solved the problem.

    
05.03.2017 / 15:15