makerofthings7
makerofthings7

Reputation: 61483

If I specify API version in the URL, should I offer an option to have it in the header as well?

I'm designing my API, and I specify an optional API version in the URL

GET /Issuer/{certificate-name}/versions?api-version=2016-10-01[&maxresults]

Should I also have one specified in the HTTP Header (for flexibility)?

What should I do if there is a conflict between the two approaches?

Upvotes: 1

Views: 241

Answers (1)

Bishoy
Bishoy

Reputation: 4025

There is no obvious advantage to allowing an input of API version from 2 different input methods (querystring, and Header). However, the disadvantage here is conflict resolution if both are specified by the client.

There is no right or wrong way of where an API version should be specified, whether in the header or the querystring. But keep in mind that URLs require parsing, while mostly done the by framework, but still a compute resource you are spending to parse the URL to extract the value from.

I (personally) prefer using the header out of simplicity. Plus it feels more cleaner to keep the URL as an address only to point to the function/intent of the client.

Upvotes: 1

Related Questions