-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate frontend to use Tapir endpoints #28
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a72e0e5
Factor out common "api" base in endpoints
lolgab 4ca2386
Bump Tapir to 1.1.0
lolgab 651e0d1
Add Tapir and dependency to shared module on frontend
lolgab b77f822
Migrate frontend to use tapir endpoints
lolgab 6dd2ae5
Organize imports
lolgab 618eff9
Run Scalafmt
lolgab 075b633
Reuse common logic in api.client
lolgab 9f0a972
Revert removal of libidn2 from vcpkgDependencies
lolgab d226967
Remove api.stabilty.scala and unused fields from Stability
lolgab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package twotm8 | ||
package frontend | ||
|
||
import scalacss.internal.LengthUnit.ex | ||
import sttp.capabilities.Effect | ||
import sttp.client3.* | ||
import sttp.model.Method | ||
|
||
import scala.concurrent.Future | ||
import scala.concurrent.duration.* | ||
|
||
case class Stability( | ||
delay: FiniteDuration = 100.millis, | ||
maxRetries: Int = 5 | ||
) | ||
|
||
class RetryingBackend[P]( | ||
delegate: SttpBackend[Future, P] | ||
)(using stability: Stability) | ||
extends DelegateSttpBackend[Future, P](delegate): | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
private given retry.Success[ | ||
(Request[?, ?], Either[Throwable, Response[?]]) | ||
]((req, res) => !RetryWhen.Default(req, res)) | ||
|
||
// The default timer is currently broken in JS | ||
// https://github.com/softwaremill/odelay/pull/19 | ||
private given odelay.Timer = odelay.js.JsTimer.newTimer | ||
|
||
override def send[T, R >: P & Effect[Future]]( | ||
request: Request[T, R] | ||
): Future[Response[T]] = | ||
retry | ||
.Backoff(stability.maxRetries, stability.delay) | ||
.apply { | ||
delegate | ||
.send(request) | ||
.transform(tryResponse => | ||
scala.util.Success((request, tryResponse.toEither)) | ||
) | ||
} | ||
.flatMap { | ||
case (_, Right(response)) => Future.successful(response) | ||
case (_, Left(exception)) => Future.failed(exception) | ||
} | ||
|
||
end RetryingBackend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MIgrating
api.stability
toFuture
s and to be used in sttp wasn't trivial, so I reimplemented an exponential backoff retrying backend using retry.I left the original file in case we want to migrate it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to remove it completely - though I would've imagined that sttp has a retying backend built-in given that both libraries are part of softwaremillverse :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be an interesting thing to try, actually! But as far as I know, there is no retry integration for sttp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened an issue here