Version Identification in API #990

Closed
opened 2025-12-29 16:27:37 +01:00 by adam · 1 comment
Owner

Originally created by @DerekTBrown on GitHub (May 24, 2017).

Would it be possible to include the API Version String in the API Endpoint (/api/), so that REST clients can validate that the version is correct?

Originally created by @DerekTBrown on GitHub (May 24, 2017). Would it be possible to include the API Version String in the API Endpoint (/api/), so that REST clients can validate that the version is correct?
adam closed this issue 2025-12-29 16:27:37 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 24, 2017):

NetBox uses request headers rather than URL parameters for versioning. The API version is indicated in the API-Version response header:

* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Date: Wed, 24 May 2017 18:25:01 GMT
< Server: WSGIServer/0.1 Python/2.7.6
< Content-Length: 549
< Vary: Accept, Cookie
< Allow: GET, PUT, PATCH, DELETE, OPTIONS
< API-Version: 2.0
< X-Frame-Options: SAMEORIGIN
< Content-Type: application/json

Requests for a version other than the current version will be rejected:

$ curl -v -H "Accept: application/json; version=1.0" http://localhost:8000/api/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8000 (#0)
> GET /api/ HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:8000
> Accept: application/json; version=1.0
> 
* HTTP 1.0, assume close after body
< HTTP/1.0 406 Not Acceptable
< Date: Wed, 24 May 2017 18:29:53 GMT
< Server: WSGIServer/0.1 Python/2.7.6
< Content-Length: 50
< Vary: Accept
< Allow: GET, HEAD, OPTIONS
< API-Version: 2.0
< X-Frame-Options: SAMEORIGIN
< Content-Type: application/json
< 
* Closing connection 0

Granted, this needs to be added to the API documentation.

@jeremystretch commented on GitHub (May 24, 2017): NetBox uses request headers rather than URL parameters for versioning. The API version is indicated in the `API-Version` response header: ``` * HTTP 1.0, assume close after body < HTTP/1.0 200 OK < Date: Wed, 24 May 2017 18:25:01 GMT < Server: WSGIServer/0.1 Python/2.7.6 < Content-Length: 549 < Vary: Accept, Cookie < Allow: GET, PUT, PATCH, DELETE, OPTIONS < API-Version: 2.0 < X-Frame-Options: SAMEORIGIN < Content-Type: application/json ``` Requests for a version other than the current version will be rejected: ``` $ curl -v -H "Accept: application/json; version=1.0" http://localhost:8000/api/ * Hostname was NOT found in DNS cache * Trying 127.0.0.1... * Connected to localhost (127.0.0.1) port 8000 (#0) > GET /api/ HTTP/1.1 > User-Agent: curl/7.35.0 > Host: localhost:8000 > Accept: application/json; version=1.0 > * HTTP 1.0, assume close after body < HTTP/1.0 406 Not Acceptable < Date: Wed, 24 May 2017 18:29:53 GMT < Server: WSGIServer/0.1 Python/2.7.6 < Content-Length: 50 < Vary: Accept < Allow: GET, HEAD, OPTIONS < API-Version: 2.0 < X-Frame-Options: SAMEORIGIN < Content-Type: application/json < * Closing connection 0 ``` Granted, this needs to be added to the API documentation.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#990