Skip to content

Commit 88dfbd9

Browse files
committed
feat: updating main, uuid, base, and json
1 parent f7b806b commit 88dfbd9

4 files changed

Lines changed: 64 additions & 30 deletions

File tree

app/main.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
11
from fastapi import FastAPI
2-
from app.routes import json_tools, uuid_tools, base64_tools, time_tools, password_tools
2+
from app.routes import (
3+
json_tools,
4+
uuid_tools,
5+
base64_tools,
6+
time_tools,
7+
password_tools
8+
)
39

4-
app = FastAPI(title="Developer Toolkit API")
10+
# Initialize the FastAPI app with metadata for documentation
11+
app = FastAPI(
12+
title="Developer Toolkit API",
13+
description="A collection of backend utilities for developers including encoding, formatting, timestamp conversion, and more.",
14+
version="1.0.0",
15+
contact={
16+
"name": "Jameelah Mercer",
17+
"email": "hello@juadocs.com",
18+
"url": "https://juadocs.com"
19+
},
20+
license_info={
21+
"name": "MIT",
22+
"url": "https://opensource.org/licenses/MIT",
23+
},
24+
)
525

26+
# Register routers for each toolkit module
627
app.include_router(json_tools.router)
728
app.include_router(uuid_tools.router)
829
app.include_router(base64_tools.router)
930
app.include_router(time_tools.router)
1031
app.include_router(password_tools.router)
1132

12-
@app.get("/")
33+
# Root route to verify the API is running
34+
@app.get("/", tags=["Root"])
1335
def read_root():
36+
"""
37+
Root endpoint that returns a welcome message.
38+
"""
1439
return {"message": "Welcome to the Developer Toolkit API!"}
1540

app/routes/base64_tools.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,31 @@
22
from pydantic import BaseModel, Field
33
import base64
44

5+
# Create a router for Base64 encoding/decoding routes
56
router = APIRouter(prefix="/tools/base64", tags=["Base64 Tools"])
67

7-
# Input model for encoding plain text
8+
# Request model for encoding input
89
class Base64EncodeInput(BaseModel):
910
content: str = Field(
1011
example="hello world",
1112
description="The plain text string to encode into Base64"
1213
)
1314

14-
# Output model for encoded result
15+
# Response model for encoded result
1516
class Base64EncodeResponse(BaseModel):
1617
encoded: str = Field(
1718
example="aGVsbG8gd29ybGQ=",
18-
description="The Base64-encoded string"
19+
description="The Base64-encoded output string"
1920
)
2021

21-
# Input model for decoding Base64 string
22+
# Request model for decoding input
2223
class Base64DecodeInput(BaseModel):
2324
encoded: str = Field(
2425
example="aGVsbG8gd29ybGQ=",
2526
description="The Base64-encoded string to decode"
2627
)
2728

28-
# Output model for decoded result
29+
# Response model for decoded result
2930
class Base64DecodeResponse(BaseModel):
3031
decoded: str = Field(
3132
example="hello world",
@@ -36,14 +37,17 @@ class Base64DecodeResponse(BaseModel):
3637
"/encode",
3738
response_model=Base64EncodeResponse,
3839
summary="Encode a string to Base64",
39-
response_description="Returns the Base64-encoded version of the input"
40+
response_description="Returns the Base64-encoded result"
4041
)
4142
def encode_base64(data: Base64EncodeInput):
4243
"""
43-
Encode a plain text string into Base64.
44+
Encode a plain text string into Base64 format.
4445
45-
Accepts a `content` field containing a UTF-8 string,
46-
and returns its Base64-encoded version.
46+
Parameters:
47+
data (Base64EncodeInput): JSON object with a 'content' field.
48+
49+
Returns:
50+
Base64EncodeResponse: Encoded Base64 string.
4751
"""
4852
try:
4953
encoded = base64.b64encode(data.content.encode("utf-8")).decode("utf-8")
@@ -54,15 +58,18 @@ def encode_base64(data: Base64EncodeInput):
5458
@router.post(
5559
"/decode",
5660
response_model=Base64DecodeResponse,
57-
summary="Decode a Base64 string to plain text",
58-
response_description="Returns the decoded string"
61+
summary="Decode a Base64 string",
62+
response_description="Returns the decoded plain text result"
5963
)
6064
def decode_base64(data: Base64DecodeInput):
6165
"""
62-
Decode a Base64 string back into plain text.
66+
Decode a Base64 string into a plain UTF-8 string.
67+
68+
Parameters:
69+
data (Base64DecodeInput): JSON object with an 'encoded' field.
6370
64-
Accepts an `encoded` field containing a Base64 string,
65-
and returns the decoded UTF-8 string.
71+
Returns:
72+
Base64DecodeResponse: Decoded plain text string.
6673
"""
6774
try:
6875
decoded_bytes = base64.b64decode(data.encoded.encode("utf-8"))

app/routes/json_tools.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
from pydantic import BaseModel, Field
33
import json
44

5+
# Create a FastAPI router with a URL prefix and tag for grouping
56
router = APIRouter(prefix="/tools/json", tags=["JSON Tools"])
67

7-
# Request model with a raw JSON string input
8+
# Request model for the JSON prettifier
89
class JSONPrettifyInput(BaseModel):
910
content: str = Field(
1011
example='{"key":"value"}',
11-
description="Raw JSON string to format"
12+
description="Raw JSON string to be formatted"
1213
)
1314

14-
# Response model with prettified output
15+
# Response model for the prettified JSON output
1516
class JSONPrettifyResponse(BaseModel):
1617
prettified: str = Field(
1718
example='{\n "key": "value"\n}',
18-
description="Formatted JSON string with indentation"
19+
description="Formatted JSON string with proper indentation"
1920
)
2021

2122
@router.post(
@@ -26,19 +27,19 @@ class JSONPrettifyResponse(BaseModel):
2627
)
2728
def prettify_json(data: JSONPrettifyInput):
2829
"""
29-
Prettify (beautify) a raw JSON string.
30+
Convert a compact JSON string into a human-readable, formatted string.
3031
31-
Accepts a compact JSON string and returns a formatted version
32-
with indentation and line breaks.
32+
Parameters:
33+
data (JSONPrettifyInput): JSON payload containing raw JSON text.
3334
3435
Returns:
35-
JSON object containing a single `prettified` key with the formatted string.
36+
JSONPrettifyResponse: A dictionary with the prettified version of the input JSON.
3637
"""
3738
try:
38-
# Parse the input JSON string to an object
39+
# Parse the raw JSON string into a Python object
3940
parsed = json.loads(data.content)
4041

41-
# Convert it back to a nicely indented string
42+
# Re-convert to JSON with indentation
4243
prettified = json.dumps(parsed, indent=4)
4344

4445
return {"prettified": prettified}

app/routes/uuid_tools.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
from pydantic import BaseModel, Field
33
import uuid
44

5+
# Create a router with a URL prefix and grouping tag
56
router = APIRouter(prefix="/tools/uuid", tags=["UUID Tools"])
67

7-
# Response model with example UUID
8+
# Response model for the UUID generator
89
class UUIDResponse(BaseModel):
910
uuid: str = Field(
1011
example="123e4567-e89b-12d3-a456-426614174000",
@@ -19,10 +20,10 @@ class UUIDResponse(BaseModel):
1920
)
2021
def generate_uuid():
2122
"""
22-
Generate a random UUID version 4.
23+
Generate a version 4 (random) UUID.
2324
2425
Returns:
25-
A JSON object containing a stringified UUID.
26+
UUIDResponse: A dictionary containing the generated UUID.
2627
"""
2728
return {"uuid": str(uuid.uuid4())}
2829

0 commit comments

Comments
 (0)