Professional Documents
Culture Documents
Ekm#1 - (Apps) Daily Quote & Encouragement Via Api
Ekm#1 - (Apps) Daily Quote & Encouragement Via Api
1. Ensure you have FastAPI and Uvicorn installed. If not, you can install them using pip:
```
```
```
```
Here, `main` refers to the name of the Python file (without the `.py` extension), and
`app` refers to the name of the FastAPI application instance created in the file.
4. Once the application is running, you can access the API Postman at
`http://127.0.0.1:8000` by default. In this case, you can access the quote endpoint at
`http://127.0.0.1:8000/quote/` and it will return a random quote.
This will start a development server using Uvicorn and you will be able to access the API
and get a random quote by making a GET request to the specified endpoint.
import random
app = FastAPI()
def generate_quote():
quotes = [
"The only way to do great work is to love what you do. - Steve Jobs",
"The only limit to our realization of tomorrow will be our doubts of today. - Franklin D.
Roosevelt",
"The best way to predict the future is to invent it. - Alan Kay"
return random.choice(quotes)
# Now, let's define a route for our API that will return a random quote
@app.get("/quote/")
def get_quote():