From 2f58ae4baf07d58f4dda58fdd7295e8966e6036d Mon Sep 17 00:00:00 2001 From: Naineel Soyantar <112230479+naineel1209@users.noreply.github.com> Date: Fri, 22 Nov 2024 12:52:14 +0000 Subject: [PATCH 1/2] wip: started with enhancing root endpoint --- server/polar/app.py | 4 ++++ server/polar/root/__init__.py | 0 server/polar/root/endpoints.py | 14 ++++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 server/polar/root/__init__.py create mode 100644 server/polar/root/endpoints.py diff --git a/server/polar/app.py b/server/polar/app.py index 26405b72e1..3b1a5ea147 100644 --- a/server/polar/app.py +++ b/server/polar/app.py @@ -41,6 +41,7 @@ from polar.postgres import create_async_engine, create_sync_engine from polar.posthog import configure_posthog from polar.redis import Redis, create_redis +from polar.root import router as root_router from polar.sentry import configure_sentry from polar.webhook.webhooks import document_webhooks from polar.worker import ArqRedis @@ -161,6 +162,9 @@ def create_app() -> FastAPI: # /healthz app.include_router(health_router) + # root endpoint + app.include_router(root_router) + app.include_router(router) document_webhooks(app) diff --git a/server/polar/root/__init__.py b/server/polar/root/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/server/polar/root/endpoints.py b/server/polar/root/endpoints.py new file mode 100644 index 0000000000..2a39be6673 --- /dev/null +++ b/server/polar/root/endpoints.py @@ -0,0 +1,14 @@ +from polar.routing import APIRouter + +router = APIRouter() + + +@router.get("/") +def get() -> dict[str, str]: + return { + "message": """ + Hello, World! This is the Polar API. + + For more information, please visit the documentation at: https://docs.polar.sh/ + """ + } From bd025b7a7f1c9bdda1bf8b6d561f8015c2be96ae Mon Sep 17 00:00:00 2001 From: Naineel Soyantar <112230479+naineel1209@users.noreply.github.com> Date: Sat, 23 Nov 2024 10:56:14 +0000 Subject: [PATCH 2/2] feat: enhanced api reference documentation --- .../src/app/(main)/docs/api/(mdx)/page.mdx | 62 +++++++++++++++++-- server/polar/app.py | 2 +- server/polar/root/endpoints.py | 8 +-- 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/clients/apps/web/src/app/(main)/docs/api/(mdx)/page.mdx b/clients/apps/web/src/app/(main)/docs/api/(mdx)/page.mdx index a1ddd8ee88..7cfef14deb 100644 --- a/clients/apps/web/src/app/(main)/docs/api/(mdx)/page.mdx +++ b/clients/apps/web/src/app/(main)/docs/api/(mdx)/page.mdx @@ -3,19 +3,69 @@ title: API Reference description: The Polar API for polar.sh keywords: api, reference, polar, polar.sh --- +import { CubeTransparentIcon, ArrowTopRightOnSquareIcon } from '@heroicons/react/24/outline' +import { ApiOutlined } from '@mui/icons-material' +import Link from 'next/link' +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from 'polarkit/components/ui/tooltip' # API Reference Welcome to the Polar API for polar.sh. This specification contains both the definitions of the Polar HTTP API and the Webhook API. -### Feedback +## Connecting -If you have any feedback or comments, reach out in the Polar API-issue, or reach out on the Polar Discord server. +<div className="flex items-center gap-2"> + <ApiOutlined className="h-6 w-6" /> + <h3 className="my-0">Polar API</h3> +</div> -We'd love to see what you've built with the API and to get your thoughts on how we can make the API better! +The production API is the primary endpoint for live operations. It provides full access to all features. Follow more examples here: [https://docs.polar.sh/developers](https://docs.polar.sh/developers) + +<div className="flex items-center gap-2 rounded-lg border bg-card p-4 my-4"> + <a className="no-underline cursor-default pointer-events-none">https://api.polar.sh</a> + <TooltipProvider> + <Tooltip> + <TooltipTrigger> + <a href="https://api.polar.sh/"> + <ArrowTopRightOnSquareIcon className="h-4 w-4" /> + </a> + </TooltipTrigger> + <TooltipContent> + <p>Open Polar API endpoint</p> + </TooltipContent> + </Tooltip> + </TooltipProvider> +</div> + +<br /> + +<div className="flex items-center gap-2"> + <CubeTransparentIcon className="h-6 w-6" /> + <h3 className="my-0">Sandbox API</h3> +</div> -### Connecting +To test Polar or work on your integration without worrying about actual money processing or breaking your live organization, you can use our sandbox environment. It's a dedicated server, completely isolated from the production instance where you can do all the experiments you want! -The Polar API is online at https://api.polar.sh. +Explore more about Sandbox API here: [https://docs.polar.sh/developers/sandbox](https://docs.polar.sh/developers/sandbox) -The [sandbox API](/docs/developers/sandbox) is at https://sandbox-api.polar.sh. +<div className="flex items-center gap-2 rounded-lg border bg-card p-4 my-4"> + <a className="no-underline cursor-default pointer-events-none">https://sandbox-api.polar.sh</a> + <TooltipProvider> + <Tooltip> + <TooltipTrigger> + <a href="https://sandbox-api.polar.sh/"> + <ArrowTopRightOnSquareIcon className="h-4 w-4" /> + </a> + </TooltipTrigger> + <TooltipContent> + <p>Open Sandbox API endpoint</p> + </TooltipContent> + </Tooltip> + </TooltipProvider> +</div> + +## Feedback + +If you have any feedback or comments, reach out in the [Polar API-issue](https://github.com/polarsource/polar/issues/), or reach out on the [Polar Discord server](https://discord.gg/Pnhfz3UThd). + +We'd love to see what you've built with the API and to get your thoughts on how we can make the API better! diff --git a/server/polar/app.py b/server/polar/app.py index 3b1a5ea147..7a76c578d1 100644 --- a/server/polar/app.py +++ b/server/polar/app.py @@ -41,7 +41,7 @@ from polar.postgres import create_async_engine, create_sync_engine from polar.posthog import configure_posthog from polar.redis import Redis, create_redis -from polar.root import router as root_router +from polar.root.endpoints import router as root_router from polar.sentry import configure_sentry from polar.webhook.webhooks import document_webhooks from polar.worker import ArqRedis diff --git a/server/polar/root/endpoints.py b/server/polar/root/endpoints.py index 2a39be6673..813edede17 100644 --- a/server/polar/root/endpoints.py +++ b/server/polar/root/endpoints.py @@ -4,11 +4,7 @@ @router.get("/") -def get() -> dict[str, str]: +async def get() -> dict[str, str]: return { - "message": """ - Hello, World! This is the Polar API. - - For more information, please visit the documentation at: https://docs.polar.sh/ - """ + "message": """Hello, World! Welcome to the Polar API for polar.sh. For more information on endpoints, please visit the documentation at: `https://docs.polar.sh/developers`""" }