feat: add new endpoint to fetch user data from placeholder API
This commit is contained in:
parent
37604999e4
commit
f3cb81b143
@ -0,0 +1,14 @@
|
|||||||
|
from fastapi import APIRouter, HTTPException
|
||||||
|
from typing import Optional, Dict
|
||||||
|
import requests
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.get("/placeholder-user", response_model=Optional[Dict])
|
||||||
|
async def get_placeholder_user(user_id: int):
|
||||||
|
try:
|
||||||
|
response = requests.get(f"https://jsonplaceholder.typicode.com/users/{user_id}")
|
||||||
|
response.raise_for_status()
|
||||||
|
return response.json()
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
raise HTTPException(status_code=400, detail=str(e))
|
@ -11,3 +11,4 @@ jose
|
|||||||
passlib
|
passlib
|
||||||
pydantic
|
pydantic
|
||||||
db
|
db
|
||||||
|
Requests
|
||||||
|
Loading…
x
Reference in New Issue
Block a user