1

I have created a post route using werkzeug.

http://localhost:8000/v1/api/<serial_id>/data

def url_map():
    tenants = [
        Submount(
            "/<serial_id>",
            [
                Rule(
                    "/data",
                    methods=["POST"],
                    endpoint=getData,
                )
            ],
        )
    ]

    api = [Submount("/api", api)]

    rules = [Submount("/v1", api)]
    return Map(rules, strict_slashes=False)


   def getData(self, request, serial_id):
        logger.error('88888888888888888888888888888888888888888888888888888888888')
        logger.error(serial_id)
        return {'status': 'ok'}

I am sending request to the path:

requests.post('http://localhost:8000/v1/api/<serial_id>/data',
                                                data= json.dumps({'data':'data'}),
                                                params={'serial_id':1}
                                                )

The problem is instead of printing 1 it print serial_id as <serial_id>.

Expected is:
88888888888888888888888888888888888888888888888888888888888
1

Actual is:
88888888888888888888888888888888888888888888888888888888888
<serial_id>
4
  • <serial_id> is what's in the URL literally, you need to look in request object. Commented Jul 29, 2020 at 9:53
  • the url should be look like that url = 'http://localhost:8000/v1/api/'+str(serial_id)+'/data' # serial_id is a dynamic value. then res = requests.post(url , data= json.dumps({'data':'data'}), params={'serial_id':1}) then response will print(res.text) Commented Jul 29, 2020 at 10:03
  • When i hit localhost:8000/v1/api/1/data, i get serial id as 1. I need a way to set the <serial_id> to 1. Commented Jul 29, 2020 at 10:26
  • werkzeug.palletsprojects.com/en/1.0.x/routing This is how we define the URLs in werkzeug Commented Jul 29, 2020 at 10:47

1 Answer 1

2

As @Md Jewele Islam states in the comments the url variable must be like:

url = 'http://localhost:8000/v1/api/{}/data'.format(str(serial_id))

and the request must be sent like:

import json
res = requests.post(url , data= json.dumps({'data':'data'}), params={'serial_id':1})

So you can print the response by:

print(res.text)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.