Learn Before
Code
FastAPI URL Pathing
You can customize the JSON response from FastAPI using the @app.get decorator. For example:
from typing import Optional from fastapi import FastAPI app = FastAPI() @app.get("/items/{item_id}") def read_item(item_id: int): if item_id == 1: return {item_id: "One"} else: return {item_id: None}
Acessing 127.0.0.1:8000/items/1 returns:
{"1":"One"}
And 127.0.0.1:8000/items/2 returns:
{"2":"null}
0
1
Updated 2021-03-29
Tags
Python Programming Language
Data Science