@@ -27,7 +27,7 @@ def output_xml(data, code, headers=None):
27
27
app = Flask (__name__ )
28
28
db = Dao ()
29
29
30
- api = Api (app , default_mediatype = 'application/xml ' )
30
+ api = Api (app , default_mediatype = 'application/json ' )
31
31
api .representations ['application/xml' ] = output_xml
32
32
33
33
@@ -153,33 +153,13 @@ def getlist():
153
153
#print ret_data
154
154
return jsonify (AllProducts = ret_data )
155
155
156
- @app .route ('/api/<userid> ' , methods = ['GET ' ,'POST ' ])
157
- def webapi (userid ):
156
+ @app .route ('/post ' , methods = ['POST ' ,'GET ' ])
157
+ def webapi ():
158
158
message = None
159
159
160
- if request .methods == 'POST' :
161
- if request .headers ['Content-Type' ] == 'text/plain' :
162
- return "Text Message: " + request .data
163
-
164
- elif request .headers ['Content-Type' ] == 'application/json' :
165
- return "JSON Message: " + json .dumps (request .json )
166
-
167
- elif request .headers ['Content-Type' ] == 'application/octet-stream' :
168
- f = open ('./binary' , 'wb' )
169
- f .write (request .data )
170
- f .close ()
171
- return "Binary message written!"
172
-
173
- else :
174
- return "415 Unsupported Media Type ;)"
175
-
176
-
177
- elif request .methods == 'GET' :
178
- users = {'1' :'john' , '2' :'steve' , '3' :'bill' }
179
- if str (userid ) in users :
180
- return jsonify ({userid :users [userid ]})
181
- else :
182
- return not_found ()
160
+ if request .method == 'POST' :
161
+ message = request .form ['username' ]
162
+ return jsonify ({'username' :message })
183
163
184
164
#print ret_data
185
165
return None
0 commit comments