Hossam Al-din Hassan
Hossam Al-din Hassan

Reputation: 51

how to run a script on server using fastApi

i'm new to fastAPI imported a script into the main.py in my fastAPI based api

import example

how to run the script when calling the url with value in the script

like http://127.0.0.1:8000/url=https://google.com

to make the script waiting for the value after "url="

Upvotes: 3

Views: 3754

Answers (1)

Miyuru
Miyuru

Reputation: 53

from fastapi import FastAPI

app = FastAPI()

@app.get("/{param}")
async def read_user_item(param: str, url: str):
    item = {"param": param, "url": url}
    return item

http://127.0.0.1:8000/index?url=https://google.com

for this output will

{"param":"index","url":"https://google.com"}

Hope this will help you as well. https://fastapi.tiangolo.com/tutorial/query-params/

Upvotes: 2

Related Questions