Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 4

[APPS] DAILY QUOTE & ENCOURAGEMENT VIA API (POSTMAN)

EKM Entry by: Rodzon Limjap

A. Here is the procedure and dependency libraries below.


To run the Python script as an API, you can use a web framework like FastAPI, which is
already being used in the provided code. Here's how you can run the Python script as an
API using FastAPI:

1. Ensure you have FastAPI and Uvicorn installed. If not, you can install them using pip:

```

pip install fastapi uvicorn

```

2. Save the corrected Python script in a file, for example, `main.py`.

Please see actual code below

3. Run the FastAPI application using Uvicorn:

```

uvicorn main:app --reload

```

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.

B. Test Result using API Postman


C. Test Result using web browser e.g IE or Chrome

D. Logging Result thru Visual Studio Code terminal

E. Actual Python codes


from fastapi import FastAPI

import random

from typing import Optional

app = FastAPI()

def generate_quote():

quotes = [

"The only way to do great work is to love what you do. - Steve Jobs",

"Innovation distinguishes between a leader and a follower. - 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():

return {"quote": generate_quote()}

You might also like