You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/concepts/api_version_parameter.md
+22-22Lines changed: 22 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,15 @@
1
-
# API Version Parameter
1
+
# API version parameter
2
2
3
-
Cadwyn adds another routing layer to FastAPI by default: by version parameter. This means that before FastAPI tries to route us to the correct route, Cadwyn will first decide on which version of the route to use based on a version parameter. Feel free to look at the example app with URL path version prefixes and arbitrary strings as versions [here](../how_to/version_with_paths_and_numbers_instead_of_headers_and_dates.md).
3
+
Cadwyn adds another routing layer to FastAPI by default: by a version parameter. This means that before FastAPI selects the correct route for the request, Cadwyn decides which version of the route will be used based on the version parameter. Feel free to look at the example app with URL path version prefixes and arbitrary strings as versions [here](../how_to/version_with_paths_and_numbers_instead_of_headers_and_dates.md).
4
4
5
-
## API Version location
5
+
## API version location
6
6
7
-
The version parameter can be passed in two different ways:
7
+
A version parameter can be passed in two different ways:
8
8
9
-
-As a custom header
10
-
-As a URL path parameter
9
+
-as a custom header
10
+
-as a URL path parameter
11
11
12
-
Cadwyn will use the following defaults:
12
+
Cadwyn uses the following defaults:
13
13
14
14
```python
15
15
from cadwyn import Cadwyn, Version, VersionBundle
@@ -45,12 +45,12 @@ app = Cadwyn(
45
45
)
46
46
```
47
47
48
-
## API Version format
48
+
## API version format
49
49
50
-
The version parameter can be formatted in two different ways:
50
+
A version parameter can be formatted in two different ways:
51
51
52
-
-As an ISO date
53
-
-As an arbitrary string
52
+
-as an ISO date
53
+
-as an arbitrary string
54
54
55
55
Cadwyn uses the following default:
56
56
@@ -63,7 +63,7 @@ app = Cadwyn(
63
63
)
64
64
```
65
65
66
-
In the example above only dates will be accepted as valid versions.
66
+
In the example above only dates are accepted as valid versions.
67
67
68
68
You can also use an arbitrary string:
69
69
@@ -80,21 +80,21 @@ app = Cadwyn(
80
80
)
81
81
```
82
82
83
-
In the example above any string will be accepted as a valid version. Arbitrary strings can be used, Cadwyn will not sort them. Cadwyn will assume their actual order matches the order of the versions in the `VersionBundle`.
83
+
In the example above any arbitrary string is accepted as a valid version. Cadwyn does not sort them, Cadwyn assumes that their actual order matches the order of the versions in the `VersionBundle`.
84
84
85
-
### API Version waterfalling
85
+
### API version waterfalling
86
86
87
-
For historical reasons, date-based routing also supports waterfalling the requests to the closest earlier version of the API if the request date parameter doesn't match any of the versions exactly.
87
+
For historical reasons, date-based routing also supports waterfalling the requests to the closest earlier version of the API if the request date parameter does not match any of the versions exactly.
88
88
89
89
If the app has two versions: 2022-01-02 and 2022-01-05, and the request date parameter is 2022-01-03, then the request will be routed to the 2022-01-02 version, as it is the closest version, but lower than the request date parameter.
90
90
91
-
An exact match is always preferred to a partial match and a request will never be matched to the higher-versioned route.
91
+
An exact match is always preferred to a partial match and a request is never matched to the higher-versioned route.
92
92
93
-
We implement routing like this because Cadwyn was born in a microservice architecture and it is extremely convenient to have waterfalling there. For example, imagine that you have two Cadwyn services: Payables and Receivables, each defining its own API versions. Payables service might contain 10 versions while Receivables service might contain only 2 versions because it didn't need as many breaking changes. If a client requests a version that does not exist in Receivables, we will waterfall to some earlier version, making Receivables behavior consistent even if API keeps getting new versions.
93
+
The routing is implemented like this because Cadwyn was born in a microservice architecture and it is extremely convenient to have waterfalling there. Assume that you have two Cadwyn services: Payables and Receivables, each defining its own API versions. Payables service might have ten versions while Receivables service might have only two versions because it did not need as many breaking changes. If a client requests a version that does not exist in Receivables, Cadwyn will waterfall to some earlier version, making Receivables behavior consistent even if API keeps getting new versions.
94
94
95
-
## API Version Parameter Title and Description
95
+
## API version parameter title and description
96
96
97
-
You can pass a title and/or a description to the `Cadwyn` constructor. It is equivalent to passing `title` and `description` to `fastapi.Path` or `fastapi.Header` constructors.
97
+
You can pass a title and/or a description to the `Cadwyn()` constructor. It is equivalent to passing `title` and `description` to `fastapi.Path()` or `fastapi.Header()` constructors.
98
98
99
99
```python
100
100
app = Cadwyn(
@@ -104,8 +104,8 @@ app = Cadwyn(
104
104
)
105
105
```
106
106
107
-
## API Version Context Variables
107
+
## API version context variables
108
108
109
-
Cadwyn automatically converts your data to a correct version and has "version checks" when dealing with side effects as described in [the section above](./version_changes.md#version-changes-with-side-effects). It can only do so using a special [context variable](https://docs.python.org/3/library/contextvars.html) that stores the current API version.
109
+
Cadwyn automatically converts your data to the correct version and has "version checks" when dealing with side effects as described in [the section above](./version_changes.md#version-changes-with-side-effects). It can only do so using a special [context variable](https://docs.python.org/3/library/contextvars.html) that stores the current API version.
110
110
111
-
You can also pass a different compatible contextvar to your `cadwyn.VersionBundle` constructor.
111
+
You can also pass a different compatible `contextvar` to your `cadwyn.VersionBundle()` constructor.
Often you will want to introduce a breaking change where one of the following is true:
3
+
Often you may want to introduce a breaking change when one of the following is true:
4
4
5
5
* Old data cannot be automatically converted to the structure of the new response
6
6
* New response cannot be automatically migrated to an older response
7
7
* Old request cannot be automatically converted to the HEAD request
8
8
9
-
This means that you are not versioning your API, you are versioning your **data**. This cannot be solved by an API versioning framework. It also makes it incredibly hard to version as you now cannot guarantee compatibility between versions. Avoid this at all costs -- all your API versions must be compatible between each other. Data versioning is not a result of a complicated use case, it is a result of **errors** when divising a new version. I am yet to meet a single case where data versioning is the right way to solve an API versioning problem.
9
+
This means that you are not versioning your API, you are versioning your **data**. Such an issue cannot be solved using an API versioning framework. It also makes it incredibly hard to version as you now cannot guarantee compatibility between versions. Avoid this at all costs — all your API versions must be compatible between each other. Data versioning is not a result of a complicated use case, it is a result of **errors** when devising a new version. I have yet to see a single case where data versioning is the right way to solve an API versioning issue.
Copy file name to clipboardExpand all lines: docs/concepts/changelogs.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
# Changelogs
2
2
3
-
Cadwyn can automatically generate API changelogs for your versions. By default they are available through the unversioned endpoint `GET /changelog`. You can also get it from`Cadwyn.generate_changelog` method.
3
+
Cadwyn can automatically generate API changelogs for your versions. By default, they are available through the unversioned endpoint `GET /changelog`. You can also access it via`Cadwyn.generate_changelog()` method.
4
4
5
5
## Hiding version changes and instructions
6
6
7
-
Sometimes you might want to do private internal version changes or instructions within the version changes that should not be visible to the public. You can do this by using the `cadwyn.hidden` function. For example:
7
+
Sometimes you might want to make private internal version changes or instructions within the version changes that should not be visible to the public. You can do this by using the `cadwyn.hidden()` function. Consider the example below:
8
8
9
9
```python
10
-
from cadwyn importhidden, VersionChange, endpoint
10
+
from cadwyn import VersionChange, endpoint, hidden
During Cadwyn's development, I went through countless resources on API Versioning. The following are the most unique and effective ones I managed to find.
3
+
While developing Cadwyn, I went through countless resources on API versioning. The following are the most unique and helpful ones I managed to find.
4
4
5
-
## Cadwyn-like API Versioning
5
+
## Cadwyn-style API versioning
6
6
7
7
### Articles
8
8
9
-
*[API Versioning at Stripe](https://stripe.com/blog/api-versioning)
10
-
*[API Versioning at Intercom](https://www.intercom.com/blog/api-versioning/)
11
-
*[Rolling Versions at Convoy](https://getconvoy.io/blog/rolling-versions)
12
-
*[Breaking Things Without Breaking Things at Keygen](https://keygen.sh/blog/breaking-things-without-breaking-things/)
13
-
*[API Versioning at LinkedIn Marketing](https://engineering.linkedin.com/blog/2022/-under-the-hood--how-we-built-api-versioning-for-linkedin-market)
9
+
*[API versioning at Stripe](https://stripe.com/blog/api-versioning)
10
+
*[API versioning at Intercom](https://www.intercom.com/blog/api-versioning/)
11
+
*[Rolling versions at Convoy](https://getconvoy.io/blog/rolling-versions)
12
+
*[Breaking things without breaking things at Keygen](https://keygen.sh/blog/breaking-things-without-breaking-things/)
13
+
*[API versioning at LinkedIn Marketing](https://engineering.linkedin.com/blog/2022/-under-the-hood--how-we-built-api-versioning-for-linkedin-market)
*[Request Migrations for Go](https://github.com/subomi/requestmigrations) (by the author of Convoy)
24
+
*[Request migrations for Go](https://github.com/subomi/requestmigrations) (by the author of Convoy)
25
25
26
26
#### Ruby
27
27
28
28
*[Gates](https://github.com/phillbaker/gates)
29
-
*[Request Migrations for Ruby](https://github.com/keygen-sh/request_migrations)
29
+
*[Request migrations for Ruby](https://github.com/keygen-sh/request_migrations)
30
30
31
31
#### PHP
32
32
33
-
*[Laravel API Migrations](https://github.com/lukepolo/laravel-api-migrations)
34
-
*[Request Migrations for PHP](https://github.com/tomschlick/request-migrations)
33
+
*[Laravel API migrations](https://github.com/lukepolo/laravel-api-migrations)
34
+
*[Request migrations for PHP](https://github.com/tomschlick/request-migrations)
35
35
36
-
## Overview articles on API Versioning
36
+
## Overview articles on API versioning
37
37
38
38
*[Developing an API](https://smartlogic.io/blog/2012-12-12-developing-an-api/)
39
39
*[API versioning has no right way](https://apisyouwonthate.com/blog/api-versioning-has-no-right-way/)
40
-
*[The tricks of API Versioning](https://thenewstack.io/tricks-api-versioning/)
41
-
*[Versioning API in Django REST Framework](https://studygyaan.com/django/versioning-api-in-django-rest-framework)
42
-
43
-
## Other articles on API Versioning
44
-
45
-
*[Postman API Platform: API Versioning](https://www.postman.com/api-platform/api-versioning/)
46
-
*[Four REST API Versioning Strategies](https://www.xmatters.com/blog/blog-four-rest-api-versioning-strategies)
47
-
*[The Ultimate Guide to Microservices Versioning Best Practices](https://www.opslevel.com/resources/the-ultimate-guide-to-microservices-versioning-best-practices)
48
-
*[ASP.NET API Versioning on GitHub](https://github.com/dotnet/aspnet-api-versioning)
49
-
*[API Versioning at SuperJob](https://habr.com/ru/companies/superjob/articles/577650/)
50
-
*[Better API Versioning with Semantic Versioning in Django REST Framework](https://mikehelmick.medium.com/django-rest-framework-better-api-versioning-with-semantic-versioning-d93908613dea)
51
-
*[How Badoo Versions its API for internal clients](https://youtu.be/M2KCu0Oq3JE)
40
+
*[The tricks of API versioning](https://thenewstack.io/tricks-api-versioning/)
41
+
*[Versioning API in Django REST framework](https://studygyaan.com/django/versioning-api-in-django-rest-framework)
42
+
43
+
## Other articles on API versioning
44
+
45
+
*[Postman API Platform: API versioning](https://www.postman.com/api-platform/api-versioning/)
46
+
*[Four REST API versioning strategies](https://www.xmatters.com/blog/blog-four-rest-api-versioning-strategies)
47
+
*[The ultimate guide to microservices versioning: best practices](https://www.opslevel.com/resources/the-ultimate-guide-to-microservices-versioning-best-practices)
48
+
*[ASP.NET API versioning on GitHub](https://github.com/dotnet/aspnet-api-versioning)
49
+
*[API versioning at SuperJob](https://habr.com/ru/companies/superjob/articles/577650/)
50
+
*[Better API versioning with semantic versioning in Django REST framework](https://mikehelmick.medium.com/django-rest-framework-better-api-versioning-with-semantic-versioning-d93908613dea)
51
+
*[How Badoo versions its API for internal clients](https://youtu.be/M2KCu0Oq3JE)
0 commit comments