title: Python FastApi GET loop
body: <p>Good day for everyone, its my first request in this service, so i am glad to see all of you^^</p>
  <p>I am have some trouble with FastApi.</p>
  <p>I have raspberry pi 3, and barcode scanner with USB interface, i now how get data with while loop, but i am need to get this data from request, so i am write async script for this:</p>
  <pre><code>from fastapi import FastAPI
  from starlette.middleware.cors import CORSMiddleware
  from starlette.requests import Request
  from starlette.responses import JSONResponse
  from services.barcode import barcode_reader
  
  app = FastAPI()
  app.add_middleware(CORSMiddleware, allow_origins=[&quot;*&quot;], allow_credentials=True, allow_methods=[&quot;*&quot;], allow_headers=[&quot;*&quot;])
  barcode = &quot;&quot;
  
  async def get_barcode():
      try:
          while True:
              # barcode = barcode_reader()
              if barcode != &quot;&quot;:
                  return barcode
      except KeyboardInterrupt:
          pass
  
  @app.get(&quot;/barcode&quot;)
  async def read_barcode():
      return await get_barcode()
      
  
  @app.post(&quot;/barcode/{barcodeStr}&quot;)
  async def write_barcode(barcodeStr: str):
      barcode = barcodeStr
      return &quot;success&quot;
  </code></pre>
  <p>But when I make a GET request, I cannot put data with a POST request, in the future I will have many more methods that will be executed constantly and I would not like one method to block the entire API.</p>
  <p>Help me please ^^</p>