From 130a9354cb07efe055d22914bbf41077a7c32caa Mon Sep 17 00:00:00 2001
From: Anson
Date: Fri, 23 May 2025 21:31:52 -0600
Subject: [PATCH] finish documenting and fixing the site
---
src/two_chainz/__init__.py | 74 ++++++++++++++++--
website/index.html | 149 ++++++++++++-------------------------
2 files changed, 117 insertions(+), 106 deletions(-)
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;
}
-
+
-
+
Quote
-
Returns a random 2 Chainz Quote in json
format like the
following example:
-
send a get
request to
https://chainz.ansonbiggs.com/api/quote https://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/alias https://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!)
Please let me know if you use it though!
@@ -224,43 +186,31 @@
Do I need an API key or is this API rate limited?
No, the API is totally free and unlimited. However, its being hosted
- by a college student so be nice.
+ on a tiny machine that is overburdened by docker containers.
Does 2 Chainz know about this?
-
- Probably not.
-
+ Probably not.
Why?
-
- Because 2 Chainz has some of the best lines in the rap game.
-
+ Because 2 Chainz has some of the best lines in the rap game.
-
-
+
+