Home > flask, python > Flask RESTful POST JSON


Using Flask-RESTful, I needed an API endpoint that accepts JSON data.

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
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: