def post(word): json_input = request.get_json() if not json_input: return jsonify('No input data provided'), HTTPStatus.BAD_REQUEST try: service = WordClassificationService() entity = service.create(json_input) if not entity: raise ValueError( 'WordClassificationService did not return a result') # TODO: Why are we not using the model schema... # model_schema = WordClassificationSchema().dump(entity) data = entity.json() return jsonify(data), HTTPStatus.OK except ValueError as err: return jsonify('Word [' + word + '] not found: ' + repr(err)), HTTPStatus.NOT_FOUND except Exception as err: return jsonify('Internal server error: ' + repr(err)), HTTPStatus.INTERNAL_SERVER_ERROR
def post(): response = None if request.is_json: try: service = WordClassificationService() # Execute analysis using the supplied builder entity = service.create(request.json) if not entity: raise ValueError('WordClassificationService did not return a result') payload = jsonpickle.encode(entity) response = make_response(payload, HTTPStatus.CREATED) except Exception as error: print('Error: ' + repr(error)) raise else: response = make_response(HTTPStatus.BAD_REQUEST) return response