# Libraries for FastAPI
from fastapi import FastAPI
from fastapi.responses import RedirectResponse
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from typing import Optional
from typing import List
from fastapi import Body
from pydantic import BaseModel


import random

"""
           _____ _____   _____ _   _ ______ ____
     /\   |  __ \_   _| |_   _| \ | |  ____/ __ \
    /  \  | |__) || |     | | |  \| | |__ | |  | |
   / /\ \ |  ___/ | |     | | | . ` |  __|| |  | |
  / ____ \| |    _| |_   _| |_| |\  | |   | |__| |
 /_/    \_\_|   |_____| |_____|_| \_|_|    \____/

The `description` is the information that gets displayed when the api is accessed from a browser and loads the base route.
Also the instance of `app` below description has info that gets displayed as well when the base route is accessed.
"""

description = """🚀
## Consumer Producer 
### Not the conventional way.
"""

# Needed for CORS
origins = ["*"]


# This is the `app` instance which passes in a series of keyword arguments
# configuring this instance of the api. The URL's are obviously fake.
app = FastAPI(
    title="Producer Consumer Backend",
    description=description,
    version="0.0.1",
    terms_of_service="http://yourdomainname.com",
    contact={
        "name": "Customer Service",
        "url": "http://yourdomainname.com/contact/",
        "email": "first.last@yourdomainname.com",
    },
    license_info={
        "name": "Apache 2.0",
        "url": "https://www.apache.org/licenses/LICENSE-2.0.html",
    },
)

# Needed for CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

"""
  _      ____   _____          _         _____ _                _____ _____ ______  _____
 | |    / __ \ / ____|   /\   | |       / ____| |        /\    / ____/ ____|  ____|/ ____|
 | |   | |  | | |       /  \  | |      | |    | |       /  \  | (___| (___ | |__  | (___
 | |   | |  | | |      / /\ \ | |      | |    | |      / /\ \  \___ \\___ \|  __|  \___ \
 | |___| |__| | |____ / ____ \| |____  | |____| |____ / ____ \ ____) |___) | |____ ____) |
 |______\____/ \_____/_/    \_\______|  \_____|______/_/    \_\_____/_____/|______|_____/

Place local classes here if you have any or in a module.
"""

# local helper classes


class Inst(BaseModel):
    op: str
    val: int
    loc: str


class InstList(BaseModel):
    inst: List[Inst] = []


"""
  _      ____   _____          _        __  __ ______ _______ _    _  ____  _____   _____
 | |    / __ \ / ____|   /\   | |      |  \/  |  ____|__   __| |  | |/ __ \|  __ \ / ____|
 | |   | |  | | |       /  \  | |      | \  / | |__     | |  | |__| | |  | | |  | | (___
 | |   | |  | | |      / /\ \ | |      | |\/| |  __|    | |  |  __  | |  | | |  | |\___ \
 | |___| |__| | |____ / ____ \| |____  | |  | | |____   | |  | |  | | |__| | |__| |____) |
 |______\____/ \_____/_/    \_\______| |_|  |_|______|  |_|  |_|  |_|\____/|_____/|_____/

Place local methods here, or in a module. Up to you.
"""

# local helper methods

"""
  _____   ____  _    _ _______ ______  _____
 |  __ \ / __ \| |  | |__   __|  ____|/ ____|
 | |__) | |  | | |  | |  | |  | |__  | (___
 |  _  /| |  | | |  | |  | |  |  __|  \___ \
 | | \ \| |__| | |__| |  | |  | |____ ____) |
 |_|  \_\\____/ \____/   |_|  |______|_____/

 This is where your routes will be defined. Remember they are really just python functions
 that will talk to whatever class you write above. Fast Api simply takes your python results
 and packagres them so they can be sent back to your programs request.
"""


@app.get("/")
async def docs_redirect():
    """Api's base route that displays the information created above in the ApiInfo section."""
    return RedirectResponse(url="/docs")


@app.get("/consume/")
async def consume():
    """
    ### Description:
        Ask for data to be consumed
    ### Params:
        None
    ### Returns:
        list : data
    """
    # get consumer data
    data = []
    for i in range(random.randint(5, 10)):
        data.append(random.randint(1, 100))

    return {"Response": "Response message.", "data": data}


@app.post("/produceOne/")
async def producerOne(inst: Inst):
    """
    ### Description:
        Recieves data  from a producer to be consumed
    ### Params:
        data : list
    ### Returns:
        bool : True = success
    """
    return {"Response": "This is my response message.", "data": inst}


@app.post("/produceMany/")
async def producerMany(inst: InstList):
    """
    ### Description:
        Recieves data  from a producer to be consumed
    ### Params:
        data : list
    ### Returns:
        bool : True = success
    """
    return {"Response": "This is my response message.", "data": inst}


"""
This main block gets run when you invoke this file. How do you invoke this file?

        python api.py 

After it is running, copy paste this into a browser: http://127.0.0.1:8080 

You should see your api's base route!

Note:
    Notice the first param below: api:app 
    The left side (api) is the name of this file (api.py without the extension)
    The right side (app) is the bearingiable name of the FastApi instance declared at the top of the file.
"""
if __name__ == "__main__":
    uvicorn.run(
        "server:app", host="127.0.0.1", port=8080, log_level="debug", reload=True
    )

097e98f5239a323339f57a8e5df0238dd355ae92
<mask token>


class Inst(BaseModel):
    op: str
    val: int
    loc: str


class InstList(BaseModel):
    inst: List[Inst] = []


<mask token>

<mask token>
app.add_middleware(CORSMiddleware, allow_origins=origins, allow_credentials
    =True, allow_methods=['*'], allow_headers=['*'])
<mask token>


class Inst(BaseModel):
    op: str
    val: int
    loc: str


class InstList(BaseModel):
    inst: List[Inst] = []


<mask token>


@app.get('/')
async def docs_redirect():
    """Api's base route that displays the information created above in the ApiInfo section."""
    return RedirectResponse(url='/docs')


@app.get('/consume/')
async def consume():
    """
    ### Description:
        Ask for data to be consumed
    ### Params:
        None
    ### Returns:
        list : data
    """
    data = []
    for i in range(random.randint(5, 10)):
        data.append(random.randint(1, 100))
    return {'Response': 'Response message.', 'data': data}


@app.post('/produceOne/')
async def producerOne(inst: Inst):
    """
    ### Description:
        Recieves data  from a producer to be consumed
    ### Params:
        data : list
    ### Returns:
        bool : True = success
    """
    return {'Response': 'This is my response message.', 'data': inst}


@app.post('/produceMany/')
async def producerMany(inst: InstList):
    """
    ### Description:
        Recieves data  from a producer to be consumed
    ### Params:
        data : list
    ### Returns:
        bool : True = success
    """
    return {'Response': 'This is my response message.', 'data': inst}


<mask token>
if __name__ == '__main__':
    uvicorn.run('server:app', host='127.0.0.1', port=8080, log_level=
        'debug', reload=True)

<mask token>
description = """🚀
## Consumer Producer 
### Not the conventional way.
"""
origins = ['*']
app = FastAPI(title='Producer Consumer Backend', description=description,
    version='0.0.1', terms_of_service='http://yourdomainname.com', contact=
    {'name': 'Customer Service', 'url':
    'http://yourdomainname.com/contact/', 'email':
    'first.last@yourdomainname.com'}, license_info={'name': 'Apache 2.0',
    'url': 'https://www.apache.org/licenses/LICENSE-2.0.html'})
app.add_middleware(CORSMiddleware, allow_origins=origins, allow_credentials
    =True, allow_methods=['*'], allow_headers=['*'])
<mask token>


class Inst(BaseModel):
    op: str
    val: int
    loc: str


class InstList(BaseModel):
    inst: List[Inst] = []


<mask token>


@app.get('/')
async def docs_redirect():
    """Api's base route that displays the information created above in the ApiInfo section."""
    return RedirectResponse(url='/docs')


@app.get('/consume/')
async def consume():
    """
    ### Description:
        Ask for data to be consumed
    ### Params:
        None
    ### Returns:
        list : data
    """
    data = []
    for i in range(random.randint(5, 10)):
        data.append(random.randint(1, 100))
    return {'Response': 'Response message.', 'data': data}


@app.post('/produceOne/')
async def producerOne(inst: Inst):
    """
    ### Description:
        Recieves data  from a producer to be consumed
    ### Params:
        data : list
    ### Returns:
        bool : True = success
    """
    return {'Response': 'This is my response message.', 'data': inst}


@app.post('/produceMany/')
async def producerMany(inst: InstList):
    """
    ### Description:
        Recieves data  from a producer to be consumed
    ### Params:
        data : list
    ### Returns:
        bool : True = success
    """
    return {'Response': 'This is my response message.', 'data': inst}


<mask token>
if __name__ == '__main__':
    uvicorn.run('server:app', host='127.0.0.1', port=8080, log_level=
        'debug', reload=True)

from fastapi import FastAPI
from fastapi.responses import RedirectResponse
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from typing import Optional
from typing import List
from fastapi import Body
from pydantic import BaseModel
import random
<mask token>
description = """🚀
## Consumer Producer 
### Not the conventional way.
"""
origins = ['*']
app = FastAPI(title='Producer Consumer Backend', description=description,
    version='0.0.1', terms_of_service='http://yourdomainname.com', contact=
    {'name': 'Customer Service', 'url':
    'http://yourdomainname.com/contact/', 'email':
    'first.last@yourdomainname.com'}, license_info={'name': 'Apache 2.0',
    'url': 'https://www.apache.org/licenses/LICENSE-2.0.html'})
app.add_middleware(CORSMiddleware, allow_origins=origins, allow_credentials
    =True, allow_methods=['*'], allow_headers=['*'])
<mask token>


class Inst(BaseModel):
    op: str
    val: int
    loc: str


class InstList(BaseModel):
    inst: List[Inst] = []


<mask token>


@app.get('/')
async def docs_redirect():
    """Api's base route that displays the information created above in the ApiInfo section."""
    return RedirectResponse(url='/docs')


@app.get('/consume/')
async def consume():
    """
    ### Description:
        Ask for data to be consumed
    ### Params:
        None
    ### Returns:
        list : data
    """
    data = []
    for i in range(random.randint(5, 10)):
        data.append(random.randint(1, 100))
    return {'Response': 'Response message.', 'data': data}


@app.post('/produceOne/')
async def producerOne(inst: Inst):
    """
    ### Description:
        Recieves data  from a producer to be consumed
    ### Params:
        data : list
    ### Returns:
        bool : True = success
    """
    return {'Response': 'This is my response message.', 'data': inst}


@app.post('/produceMany/')
async def producerMany(inst: InstList):
    """
    ### Description:
        Recieves data  from a producer to be consumed
    ### Params:
        data : list
    ### Returns:
        bool : True = success
    """
    return {'Response': 'This is my response message.', 'data': inst}


<mask token>
if __name__ == '__main__':
    uvicorn.run('server:app', host='127.0.0.1', port=8080, log_level=
        'debug', reload=True)

# Libraries for FastAPI
from fastapi import FastAPI
from fastapi.responses import RedirectResponse
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from typing import Optional
from typing import List
from fastapi import Body
from pydantic import BaseModel


import random

"""
           _____ _____   _____ _   _ ______ ____
     /\   |  __ \_   _| |_   _| \ | |  ____/ __ \
    /  \  | |__) || |     | | |  \| | |__ | |  | |
   / /\ \ |  ___/ | |     | | | . ` |  __|| |  | |
  / ____ \| |    _| |_   _| |_| |\  | |   | |__| |
 /_/    \_\_|   |_____| |_____|_| \_|_|    \____/

The `description` is the information that gets displayed when the api is accessed from a browser and loads the base route.
Also the instance of `app` below description has info that gets displayed as well when the base route is accessed.
"""

description = """🚀
## Consumer Producer 
### Not the conventional way.
"""

# Needed for CORS
origins = ["*"]


# This is the `app` instance which passes in a series of keyword arguments
# configuring this instance of the api. The URL's are obviously fake.
app = FastAPI(
    title="Producer Consumer Backend",
    description=description,
    version="0.0.1",
    terms_of_service="http://yourdomainname.com",
    contact={
        "name": "Customer Service",
        "url": "http://yourdomainname.com/contact/",
        "email": "first.last@yourdomainname.com",
    },
    license_info={
        "name": "Apache 2.0",
        "url": "https://www.apache.org/licenses/LICENSE-2.0.html",
    },
)

# Needed for CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

"""
  _      ____   _____          _         _____ _                _____ _____ ______  _____
 | |    / __ \ / ____|   /\   | |       / ____| |        /\    / ____/ ____|  ____|/ ____|
 | |   | |  | | |       /  \  | |      | |    | |       /  \  | (___| (___ | |__  | (___
 | |   | |  | | |      / /\ \ | |      | |    | |      / /\ \  \___ \\___ \|  __|  \___ \
 | |___| |__| | |____ / ____ \| |____  | |____| |____ / ____ \ ____) |___) | |____ ____) |
 |______\____/ \_____/_/    \_\______|  \_____|______/_/    \_\_____/_____/|______|_____/

Place local classes here if you have any or in a module.
"""

# local helper classes


class Inst(BaseModel):
    op: str
    val: int
    loc: str


class InstList(BaseModel):
    inst: List[Inst] = []


"""
  _      ____   _____          _        __  __ ______ _______ _    _  ____  _____   _____
 | |    / __ \ / ____|   /\   | |      |  \/  |  ____|__   __| |  | |/ __ \|  __ \ / ____|
 | |   | |  | | |       /  \  | |      | \  / | |__     | |  | |__| | |  | | |  | | (___
 | |   | |  | | |      / /\ \ | |      | |\/| |  __|    | |  |  __  | |  | | |  | |\___ \
 | |___| |__| | |____ / ____ \| |____  | |  | | |____   | |  | |  | | |__| | |__| |____) |
 |______\____/ \_____/_/    \_\______| |_|  |_|______|  |_|  |_|  |_|\____/|_____/|_____/

Place local methods here, or in a module. Up to you.
"""

# local helper methods

"""
  _____   ____  _    _ _______ ______  _____
 |  __ \ / __ \| |  | |__   __|  ____|/ ____|
 | |__) | |  | | |  | |  | |  | |__  | (___
 |  _  /| |  | | |  | |  | |  |  __|  \___ \
 | | \ \| |__| | |__| |  | |  | |____ ____) |
 |_|  \_\\____/ \____/   |_|  |______|_____/

 This is where your routes will be defined. Remember they are really just python functions
 that will talk to whatever class you write above. Fast Api simply takes your python results
 and packagres them so they can be sent back to your programs request.
"""


@app.get("/")
async def docs_redirect():
    """Api's base route that displays the information created above in the ApiInfo section."""
    return RedirectResponse(url="/docs")


@app.get("/consume/")
async def consume():
    """
    ### Description:
        Ask for data to be consumed
    ### Params:
        None
    ### Returns:
        list : data
    """
    # get consumer data
    data = []
    for i in range(random.randint(5, 10)):
        data.append(random.randint(1, 100))

    return {"Response": "Response message.", "data": data}


@app.post("/produceOne/")
async def producerOne(inst: Inst):
    """
    ### Description:
        Recieves data  from a producer to be consumed
    ### Params:
        data : list
    ### Returns:
        bool : True = success
    """
    return {"Response": "This is my response message.", "data": inst}


@app.post("/produceMany/")
async def producerMany(inst: InstList):
    """
    ### Description:
        Recieves data  from a producer to be consumed
    ### Params:
        data : list
    ### Returns:
        bool : True = success
    """
    return {"Response": "This is my response message.", "data": inst}


"""
This main block gets run when you invoke this file. How do you invoke this file?

        python api.py 

After it is running, copy paste this into a browser: http://127.0.0.1:8080 

You should see your api's base route!

Note:
    Notice the first param below: api:app 
    The left side (api) is the name of this file (api.py without the extension)
    The right side (app) is the bearingiable name of the FastApi instance declared at the top of the file.
"""
if __name__ == "__main__":
    uvicorn.run(
        "server:app", host="127.0.0.1", port=8080, log_level="debug", reload=True
    )
