Last active
January 24, 2021 14:50
-
-
Save 4OH4/3baac8ba8ac13d3ae220a69e6db59b64 to your computer and use it in GitHub Desktop.
FastAPI endpoint that runs a calculation and returns result and metadata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fastapi import APIRouter | |
from service.core.models.output import MessageOutput | |
from service.core.models.input import MessageInput | |
from service.core.logic.business_logic import run_prime_factor_calculation | |
router = APIRouter() | |
@router.post("/hello", response_model=MessageOutput, tags=["hello post"]) | |
def hello_endpoint(inputs: MessageInput): | |
# Respond to requests on the hello endpoint | |
n, largest_prime_factor, elapsed_time = run_prime_factor_calculation() | |
return { | |
"message1": "Hello, world!", | |
"message2": f"The largest prime factor of {n} is {largest_prime_factor}. Calculation took {elapsed_time:0.3f} seconds.", | |
"n": n, | |
"largest_prime_factor": largest_prime_factor, | |
"elapsed_time": elapsed_time, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment