I am trying to test the basic HTTP requests in my simple rest api using Flask framework in Python. The GET method worked just fine not the POST method yet. here is the route:
@app.route('/lang', methods=['POST'])
def addOne():
language = {'name' : request.json['name']}
languages.append(language)
return jsonify({'languages' : languages})
My languages dictionary:
languages = [{'name' : 'JavaScript'},{'name' : 'Java'}, {'name' : 'Python'}]
I am trying to use Postman application to post a new language to the dictionary, here is the request:
http://127.0.0.1:8080/lang
And in the body, row I placed this:
{"name" : "C++"}
It gives me this error:
File "/home/pi/IoT_api/restful.py", line 22, in addOne
language = {'name' : request.json['name']}
TypeError: 'NoneType' object has no attribute '__getitem__'