Archive
Posts Tagged ‘httpie’
Flask RESTful POST JSON
July 17, 2016
Leave a comment
Problem
Using Flask-RESTful, I needed an API endpoint that accepts JSON data.
Solution
I found the solution here: http://stackoverflow.com/questions/22273671/flask-restful-post-json-fails. You can copy / paste that code. Note that the JSON data is POSTed to your API endpoint, thus you need to implement the post() method.
However, how to test it?
1) using cURL:
$ curl -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d "{\"Hello\":\"Karl\"}" http://domain/your_api_endpoint
Damn, that’s compicated, right? Is there an easier way?
2) using httpie:
You can install httpie with your favorite package manager. Then:
$ http POST http://domain/your_api_endpoint Hello=Karl
Categories: flask, python
curl, Flask-RESTful, httpie, post request, REST API
