how to send parameters using curl X post in Dockercontainer

94 Views Asked by At

I am running a Dockercontainer. My Falcon app.py looks like:

import falcon

class Workers:
    def on_post(self, expedice, celkem_pracovniku, req, resp):
        
        output = str(
            {
                "expedice": expedice,
                "celkem_pracovniku": celkem_pracovniku

            }
        )


        resp.text = output

        resp.status = falcon.HTTP_OK


app = application = falcon.API()
app.add_route("/pozice_skladApi/v1/pracovnici", Workers())

I am running a docker image on port 8082:80, but I dont now how can I run the /pozice_skladApi/v1/pracovnici exactly. I try:

curl -X POST http://localhost:8082/pozice_skladApi/v1/pracovnici -d "knihy-praha" 10 but I got {"title": "500 Internal Server Error"}. What I do wrong, please?

1

There are 1 best solutions below

0
vojtam On BEST ANSWER

The problem was in the on_post function. Correct form is:

    def on_post(self, req, resp):

        try:
            data = req.media
        except:
            raise falcon.HTTPBadRequest(description="Missing post data.")

        expedice = data.get("expedice")
        celkem_pracovniku = data.get("celkem_pracovniku")

Then you can use following command in the terminal: curl -X POST -H "Content-Type: application/json" -d '{"expedice": "knihy-praha", "celkem_pracovniku": 10}' http://localhost:8082/pozice_skladApi/v1/pracovnici