def create_pets(): data = {} # Check for form submission data if request.headers.get('Content-Type') == 'application/x-www-form-urlencoded': data = {'name': request.form['name'], 'category': request.form['category']} else: data = request.get_json() pet = Pet() pet.deserialize(data) pet.save() message = pet.serialize() return make_response(jsonify(message), status.HTTP_201_CREATED, {'Location': pet.self_url() })
def create_pets(): """ Creates a Pet This endpoint will create a Pet based the data in the body that is posted --- tags: - Pets consumes: - application/json produces: - application/json parameters: - in: body name: body required: true schema: id: data required: - name - category properties: name: type: string description: name for the Pet category: type: string description: the category of pet (dog, cat, etc.) responses: 201: description: Pet created schema: id: Pet properties: id: type: integer description: unique id assigned internally by service name: type: string description: the pets's name category: type: string description: the category of pet (e.g., dog, cat, fish, etc.) 400: description: Bad Request (the posted data was not valid) """ pet = Pet() pet.deserialize(request.get_json()) pet.save() message = pet.serialize() return make_response(jsonify(message), status.HTTP_201_CREATED, {'Location': pet.self_url() })