Skip to content

apiVersion controls HTTP header, not media type. - #33

Merged
brandonchinn178 merged 1 commit into
brandonchinn178:mainfrom
chungyc:version
May 2, 2023
Merged

brandonchinn178 merged 1 commit into
brandonchinn178:mainfrom
chungyc:version

Conversation

@chungyc

@chungyc chungyc commented Apr 8, 2023

Copy link
Copy Markdown
Contributor

According to "Media types", the media type no longer needs to include the API version, and in fact, it will be ignored. Instead, it is supposed to be specified in the X-GitHub-Api-Version HTTP header. This change will make the media type always be application/vnd.github+json, and instead will include the API version in the HTTP header. It will not set the HTTP header if apiVersion is empty.

This does not change the interface. It would be nice to avoid having to deal with apiVersion if one does not intend to set it, but a user agent is supposedly required, so a defaultSettings function may not be the best approach. I'm not sure what a good approach would be, or what you would like it to be, so this pull request ignores the issue for now.

Interestingly, v3 is no longer a support version. The tests will pass with apiVersion set to the string 2022-11-28, but it seems less than ideal to have a test that will definitely start failing when this version is no longer supported.

This almost resolves #32.

@brandonchinn178

Copy link
Copy Markdown
Owner

Sorry for the delay in reviewing — you opened the PR right when my company was acquired and I had to figure out transferring the repos to my personal account. Will review shortly!

@brandonchinn178 brandonchinn178 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@brandonchinn178

Copy link
Copy Markdown
Owner

but a user agent is supposedly required, so a defaultSettings function may not be the best approach

Right, but you could do

defaultSettings :: UserAgent -> Settings

Or, if you want to be extra fancy

data Settings userAgent = Settings
  { token :: Maybe Token
  , userAgent :: userAgent
  , apiVersion :: String
  }

type UninitializedSettings = Settings (Maybe String)
type FinalizedSettings = Settings String

defaultSettings :: UninitializedSettings
defaultSettings = Settings Nothing Nothing ""

initManager :: FinalizedSettings -> IO Manager

-- will not type check!
initManager defaultSettings

-- will type check
initManager defaultSettings{userAgent = "asdf"}

I could do this separately, though

@brandonchinn178

Copy link
Copy Markdown
Owner

@chungyc

chungyc commented May 2, 2023

Copy link
Copy Markdown
Contributor Author

The formatting should be fixed now. (Hopefully without another formatting mistake.)

@brandonchinn178
brandonchinn178 merged commit 68fdb75 into brandonchinn178:main May 2, 2023
@chungyc
chungyc deleted the version branch May 2, 2023 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Media type no longer requires API version

2 participants