Skip to content

Commit 7c84c17

Browse files
committed
adding stuff
1 parent 9e38221 commit 7c84c17

3 files changed

Lines changed: 72 additions & 2 deletions

File tree

2.13 KB
Binary file not shown.

app.py

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,73 @@ def post(self):
127127
else:
128128
return {"message": "Failed to add record"}, 500
129129

130-
130+
class StringGenerator(Resource):
131+
def get(self):
132+
"""
133+
This method responds to the GET request for this endpoint and returns the data in uppercase.
134+
---
135+
tags:
136+
- Text Processing
137+
parameters:
138+
- name: message
139+
in: query
140+
type: string
141+
required: true
142+
description: The text to be converted to uppercase dude!
143+
- name: duplication_factor
144+
in: query
145+
type: integer
146+
required: false
147+
description: number of times to duplicates the text (default is 1)
148+
- name: capitalization
149+
in: query
150+
type: string
151+
required: false
152+
enum: [UPPER, LOWER]
153+
description: Capitalization style UPPER, LOWER, or None (default)
154+
responses:
155+
200:
156+
description: A successful GET request
157+
content:
158+
application/json:
159+
schema:
160+
type: object
161+
properties:
162+
generated_text:
163+
type: string
164+
description: The generated text
165+
"""
166+
167+
args = request.args
168+
message = args["message"]
169+
170+
duplication_factor = int(args.get("duplication_factor",1))
171+
capitalization = args.get("capitalization", None)
172+
173+
if capitalization == "UPPER":
174+
message = message.upper()
175+
elif capitalization == "LOWER":
176+
message = message.lower()
177+
generated_text = (message + " ") * duplication_factor
178+
return {"generated_text": generated_text}, 200
131179

132180
api.add_resource(AddRecord, "/add-record")
133181
api.add_resource(Records, "/records")
134182
api.add_resource(UppercaseText, "/uppercase")
183+
api.add_resource(StringGenerator,"/generator")
135184

136185
if __name__ == "__main__":
137-
app.run(debug=True)
186+
app.run(debug=True)
187+
188+
#
189+
#In this code, we have a Flask application with a RESTful API. The application has four endpoints: `/generate`, `/uppercase`, `/records`, and `/add-record`. Each endpoint corresponds to a different resource in the `resources` module.
190+
#
191+
#The `StringGenerator` resource handles the `/generate` endpoint. It takes a message and optional parameters for duplication factor and capitalization style. The message is then processed according to the provided parameters and returned as a generated text.
192+
#
193+
#The `UppercaseText` resource handles the `/uppercase` endpoint. It takes a text and converts it to uppercase.
194+
#
195+
#The `Records` resource handles the `/records` endpoint. It retrieves a specified number of books from the database and returns them as a list of dictionaries.
196+
#
197+
#The `AddRecord` resource handles the `/add-record` endpoint. It takes a JSON object containing a book and a rating, and adds a new record to the database.
198+
#
199+
#The `flasgger` module is used

testing.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import requests
2+
import json
3+
4+
url_endpoint = "http://127.0.0.1:5000/uppercase"
5+
resp = requests.get(url_endpoint, params = {"text" : "this is some text"})
6+
7+
print(resp.json())
8+
print(resp.status_code)

0 commit comments

Comments
 (0)