diff --git a/api_request.py b/api_request.py new file mode 100644 index 0000000..521c8de --- /dev/null +++ b/api_request.py @@ -0,0 +1,12 @@ +import requests + +base_url = "https://book-review-api-v7t4.onrender.com/process-text" + +params = { + "text": "Hello World", + "duplication_factor": 30, + "capitalization": "UPPER" +} + +response = requests.get(base_url, params=params) +print(response.json()) \ No newline at end of file diff --git a/main_template.py b/main_template.py index 2b15666..7bbf43b 100644 --- a/main_template.py +++ b/main_template.py @@ -34,9 +34,69 @@ def get(self): """ text = request.args.get('text') - return jsonify({"text": text.upper()}) + return {"text": text.upper()}, 200 + +class ProcessText(Resource): + + def get(self): + """ + This method responds to the GET request for this endpoint and processes text + based on duplication and capitalization rules. + --- + tags: + - Text Processing + parameters: + - name: text + in: query + type: string + required: true + description: The text to be processed + + - name: duplication_factor + in: query + type: integer + required: false + default: 1 + description: Number of times to repeat the text on new lines + + - name: capitalization + in: query + type: string + required: false + enum: [UPPER, LOWER, None] + default: None + description: Capitalization rule to apply to the text + responses: + 200: + description: A successful GET request + content: + application/json: + schema: + type: object + properties: + result: + type: string + description: The processed text + """ + text = request.args.get("text") + duplication_factor = request.args.get("duplication_factor", default=1, type=int) + capitalization = request.args.get("capitalization", default=None) + + # Apply capitalization + if capitalization == "UPPER": + text = text.upper() + elif capitalization == "LOWER": + text = text.lower() + + # Duplicate text on new lines + result = "\n".join([text] * max(duplication_factor, 1)) + + return jsonify({"result": result}) + +api.add_resource(ProcessText, "/process-text") api.add_resource(UppercaseText, "/uppercase") if __name__ == "__main__": - app.run(debug=True) \ No newline at end of file + app.run(debug=True) + \ No newline at end of file