Am using Python 2.7.6 along with web.py server to experiment with some simple Rest calls...
Wish to send a JSON payload to my server and then print the value of the payload...
Sample payload
{"name":"Joe"}
Here's my python script
#!/usr/bin/env python
import web
import json
urls = (
'/hello/', 'index'
)
class index:
def POST(self):
# How to obtain the name key and then print the value?
print "Hello " + value + "!"
if __name__ == '__main__':
app = web.application(urls, globals())
app.run()
Here's my cURL command:
curl -H "Content-Type: application/json" -X POST -d '{"name":"Joe"}' http://localhost:8080/hello
Am expecting this for the response (plain text):
Hello Joe!
Thank you for taking the time to read this...
You have to parse the json:
Also, make sure you're url is
http://localhost:8080/hello/
in yourcURL
request; you havehttp://localhost:8080/hello
in your example, which throws an error.