-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathviews_api.py
More file actions
35 lines (27 loc) · 1.04 KB
/
views_api.py
File metadata and controls
35 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from http import HTTPStatus
import httpx
from fastapi import APIRouter, Depends, HTTPException
from lnbits.decorators import require_invoice_key
from .models import Example
example_ext_api = APIRouter()
# views_api.py is for you API endpoints that could be hit by another service
@example_ext_api.get("/api/v1/test/{example_data}", description="Example API endpoint")
async def api_example(example_data: str) -> Example:
if example_data != "00000000":
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST,
detail="Invalid example data",
)
# Do some python things and return the data
return Example(id="2", wallet=example_data)
@example_ext_api.get(
"/api/v1/vetted",
description="Get the vetted extension readme",
dependencies=[Depends(require_invoice_key)],
)
async def api_get_vetted():
async with httpx.AsyncClient() as client:
resp = await client.get(
"https://raw.githubusercontent.com/lnbits/lnbits-extensions/main/README.md"
)
return resp.text