Reputation: 2294
I am using Akka-HTTP. I have the following URI's
/a
/b
I will receive the HIT on /a
URI and I have a condition when that condition will be fulfilled then I want to redirect to /b
URI
If that condition is not fulfilled then I am returning BAD REQUEST
Now the issue is in Akka-HTTP redirect URI is of type Standard Route and I want to return HTTP Response due to this I am unable to run the code.
Can anyone tell me how to redirect with HTTP Response type in Akka-HTTP?
Upvotes: 1
Views: 327
Reputation: 2294
To redirect from one URI to another in Akka-HTTP, We can use the same HTTP response type.
HttpResponse(status = StatusCodes.PermanentRedirect, headers = headers.Location(Uri("URI/End Point of Akka-http to Redirect")) :: Nil, entity = response)
This method will redirect the incoming request to the URI provided in the Location
part of a header.
Thanks
Upvotes: 1