How to capture the query string of a Restful request

Asked

Viewed 384 times

1

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: search 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) 

1 answer

0


I would like to record how we managed to 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

That solved the problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.