Skip to content
Discussion options

You must be logged in to vote

This will work for you:

curl -X POST "http://127.0.0.1:8000/" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{\"link\":\"BHDH\",\"target\":\"https://google.fr\",\"extras\":\"{\\\"code\\\": \\\"ABCDE\\\"}\"}"

Code to test:

from fastapi import FastAPI
from typing import Optional, Any, Dict
from pydantic import BaseModel, HttpUrl, Json

class Link(BaseModel):
    link: str
    target: HttpUrl
    extras: Json[Dict[str, Any]]

app = FastAPI()

@app.post("/")
async def home(link: Link):
    return link

Swagger input:

{
  "link": "BHDH",
  "target": "https://google.fr",
  "extras": "{\"code\": \"ABCDE\"}"
}

But... I do believe that you don't want to do this 😅
That whole…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Kludex
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
3 participants
Converted from issue

This discussion was converted from issue #3000 on February 27, 2023 23:00.