diff --git a/src/two_chainz/__init__.py b/src/two_chainz/__init__.py index df95a2a..68f1e87 100644 --- a/src/two_chainz/__init__.py +++ b/src/two_chainz/__init__.py @@ -8,7 +8,10 @@ from fastapi import FastAPI from fastapi.middleware.trustedhost import TrustedHostMiddleware from fastapi.staticfiles import StaticFiles -app = FastAPI() +app = FastAPI( + title="2 Chainz REST", + description="A simple API to get 2 Chainz quotes and aliases. See 2chainz.ansonbiggs.com for a full explanation.", +) app.add_middleware( TrustedHostMiddleware, allowed_hosts=["*"], @@ -29,21 +32,80 @@ def read_data() -> dict[str, str]: data = read_data() -@app.get("/api/") -async def ping(): +@app.get( + "/api/", + summary="Health Check", + description="Check API health status and uptime", + response_description="Health status with timestamp and uptime", + tags=["Health"], + responses={ + 200: { + "description": "Successful health check", + "content": { + "application/json": { + "example": { + "status": "ok", + "timestamp": "2025-05-24T10:30:00", + "uptime_seconds": "3600.5", + } + } + }, + } + }, +) +async def ping() -> dict[str, str]: + """ + Endpoint to check on the health of the API and to help diagnose issues. + + Returns current status, timestamp, and uptime information. + """ return { "status": "ok", "timestamp": datetime.now().isoformat(), - "uptime_seconds": round(time.time() - start_time, 2), + "uptime_seconds": str(round(time.time() - start_time, 2)), } -@app.get("/api/quote") +@app.get( + "/api/quote", + summary="2 Chainz Quote", + description="Get a quote from 2 Chainz", + tags=["Data"], + responses={ + 200: { + "description": "Successful quote", + "content": { + "application/json": { + "example": { + "quote": "Wood grain chestnut, titty fuck chest nut", + } + } + }, + } + }, +) async def quote(): return {"quote": random.choice(data["quotes"])} -@app.get("/api/alias") +@app.get( + "/api/alias", + summary="2 Chainz Alias", + description="Get one of 2 Chainz many aliases", + tags=["Data"], + responses={ + 200: { + "description": "Successful alias", + "content": { + "application/json": { + "example": { + "alias": "2 Chainz", + } + } + }, + } + }, +) async def alias(): return {"alias": random.choice(data["aliases"])} diff --git a/website/index.html b/website/index.html index 3fac336..a399f82 100644 --- a/website/index.html +++ b/website/index.html @@ -40,106 +40,67 @@ :root { --color: darkviolet; --color-bg-secondary: black; - } - - @media screen and (max-width: 400px) { - #scroll-icon { - display: none; - } + --color-link: darkviolet; } -
+
-
-
- +
+
+ TRUUUUUUUU
- 2 Chainz
-

+

-
- New Quote
-
- Tweet Quote -
-

- + + New Quote + + +
+
-
+

Usage

+

+ For exhaustive and up to date documentation see + /docs +

Quote -

Returns a random 2 Chainz Quote in json format like the following example:

-

send a get request to https://chainz.ansonbiggs.com/api/quotehttps://2chainz.ansonbiggs.com/api/quote

{
-          "quote": "I got a pocket full of money, it got me walking all slew-foot"
-        }
- -
- Parameters - -

- This endpoint also supports an optional batch parameter - to get more than one quote per request. Maximum quotes that the - endpoint will return is the amount of quotes in - quotes.py - and is subject to change. An example return from - - https://chainz.ansonbiggs.com/api/quote?batch=2 -

- -
{
-          "quotes": [
-          "I'm in the kitchen. Yams errrrrwhere.",
-          "Started from the trap, now I rap"
-          ]
-        }
-
+ "quote": "I got a pocket full of money, it got me walking all slew-foot" +}
-
Alias +
+ Alias

Returns a random 2 Chainz alias in json format. The return values are weighted and a full list can be seen in @@ -151,20 +112,21 @@

send a get request to https://chainz.ansonbiggs.com/api/aliashttps://2chainz.ansonbiggs.com/api/alias

{
-          "alias": "Dos Cadenas"
-        }
+ "alias": "Dos Cadenas" +}

- Projects built using 2chainz.ansonbiggs.com (Your project could be here!) + Projects built using 2chainz.ansonbiggs.com (Your project could be + here!)

- - + +