title: how to send information(data) from a FastAPI server(client) to another FastAPI(model)
body: <p>I am a newbie in RESTful API...</p>
  <p>so I am trying to deploy two servers (client and model). The main idea is :</p>
  <ul>
  <li>Client uploads his images on the client server, the client server(port 8000) will make some transformations</li>
  <li>then I want the client server to make a post (with transformed data) to another server (also using FastAPI at port 8008).</li>
  </ul>
  <p>Currently, I am strugling with the client server part, how to do a post to another server ?</p>
  <pre class="lang-py prettyprint-override"><code>
  # Define a flask app
  app = FastAPI()
  
  app.mount(&quot;/static&quot;, StaticFiles(directory=&quot;static&quot;), name=&quot;static&quot;)
  
  templates = Jinja2Templates(directory=&quot;./templates&quot;)
  
  origins = [&quot;*&quot;]
  methods = [&quot;*&quot;]
  headers = [&quot;*&quot;]
  
  
  app.add_middleware(
      CORSMiddleware, 
      allow_origins = origins,
      allow_credentials = True,
      allow_methods = methods,
      allow_headers = headers    
  )
  
  
  @app.get('/', response_class=HTMLResponse)
  def root(request: Request):
          return templates.TemplateResponse(&quot;index.html&quot;, {&quot;request&quot;: request})
      #render_template('index.html')
  
  
  
  #here the client will upload his image to the server
  #and then encrypt it in the same button
  @app.post('/encrypt', status_code=200)
  async def upload_img(f: UploadFile = File(...)):
  
          ret = {}
          logger.debug(f)
          #base_path = &quot;uploads&quot;
          # filename = &quot;predict.jpg&quot;
          f.filename = &quot;predict.jpg&quot;
          base_path = os.path.dirname(__file__)
          file_path = os.path.join(base_path, 'uploads',secure_filename(f.filename))
          os.makedirs(base_path, exist_ok=True)
          try:
              with open(file_path, &quot;wb&quot;) as buffer:
                  shutil.copyfileobj(f.file, buffer)
          except Exception as e:
              print(&quot;Error: {}&quot;.format(str(e)))
  
  
          image_info = {&quot;filename&quot;: f.filename,  &quot;image&quot;: f}
  
          #preprocess image
          plain_input = load_input(f)
          #create a public context and drop sk
          ctx, sk = create_ctx()
          
          #encrypt 
          enc_input = prepare_input(ctx, plain_input)
          enc_input_serialize = enc_input.serialize()
  
          # la tu dois faire un post au serveur
          return  sk
  
  
  
  class inference_param(BaseModel):
      context : bytes
      enc_input : bytes
  
  
  @app.post(&quot;/data&quot;) #send data to the model server
  async def send_data(data : inference_param):
      return data
  
  
  
  </code></pre>