Add HasApiVersion trait for API versioning - #564
Merged
Merged
Conversation
JonPurvis
force-pushed
the
api-versioning
branch
from
September 29, 2026 14:10
79fce73 to
593d2c9
Compare
JonPurvis
marked this pull request as ready for review
September 29, 2026 14:35
Sammyjo20
requested changes
Oct 2, 2026
Sammyjo20
approved these changes
Oct 3, 2026
JonPurvis
commented
Oct 3, 2026
JonPurvis
left a comment
Contributor
Author
There was a problem hiding this comment.
Yes!!
I can't approve my own PR, BUT, here's a 👍
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
Lots of APIs version their surface in different ways:
Stripe-Version: 2026-08-26.dahlia, Stripe-style version strings)?api-version=2026-10)/v1beta/...)https://v2.api.provider.com)This PR adds a small opt-in plugin so versioning is declarative on the connector/request instead of hand-rolled in
boot()/ middleware. It also makes it easy to override the default: set a version on the connector, then callsetApiVersion()on a specific request when one endpoint needs a different version.Summary
Saloon\Traits\Plugins\HasApiVersionplugin withsetApiVersion()/getApiVersion()Saloon\Enums\VersionMode:Header,QueryParam,Subdomain,UrlPath$versionKey(defaultapi-version){version}placeholder replacement for path/subdomain modes$apiVersionisnullUsage
Header
Sends
Stripe-Version: 2026-08-26.dahlia.Query param
Sends
?api-version=2026-10.URL path
Becomes
https://generativelanguage.googleapis.com/v1beta.Subdomain
Becomes
https://v2.api.provider.com.Runtime override
Useful when most of an API shares one version, but a single endpoint still needs an older (or newer) one — e.g. a beta route, a deprecated migration path, or a vendor that versioned only part of their surface.
Prefer the request override when only that one call should differ. Prefer the connector override when you want the new version applied to all requests sent through that connector.