title: How to call rest API from another server scala
body: <p>I am new in scala. Currently, to create rest API I'm using the spray. Now I want to consume API from another server. I'm calling this API on every key-stroke from UI. I'm aborting the request using AbortController if the user keeps typing and the previous request is in pending status. To hit other server request, I'm using spray-client. Which goes something like this:</p>
  
  <pre><code>def completeService(completeRequest: CompleteRequest): Future[HttpResponse] = {
  
    val pipeline: HttpRequest =&gt; Future[HttpResponse] = sendReceive ~&gt; unmarshal[HttpResponse]
    val response: Future[HttpResponse] = pipeline(Post(someremoteUrl.concat("complete"), completeRequest)
     ~&gt; addHeader("demo", "test"))
    response
  }
  </code></pre>
  
  <p>I'm able to access using this above code. And I'm getting the expected response. But the thing is time-consuming. It creates new TCP connection and communicates with the host, hits the API gives the response then terminates the connection. Here while terminating it sits idle for sometimes and didn't accept a new connection. </p>
  
  <p>Is there any alternative way to do this?</p>