I am writing a automatic versioning library.
With this library, an API server can support many backward incompatible versions without changing its core logic.
The sample API server support POST localhost:8080/
{
"name": "Zhi Qu"
}
- Nylas-Api-Version: 1.0
- Metadata: :
- language-code=-
{
"id": "af9c3b85-86c5-4771-b07f-22440de6d582",
"name": "Zhi Qu",
"created_time": 1657150876
}
- Metadata: :
{
"first_name": "Zhi",
"last_name": "Qu"
}
- Nylas-Api-Version: 1.0
- Client-Metadata: hello:world
- lang:
- region:
{
"id": "c497668b-89c7-48cd-b659-867f3287b023",
"name": "Zhi Qu"
}
- Client-Metadata: hello:world
Version 1.1 is not backward compatible with version 1.0. Specifically:
- Request body:
name
field splitted into two fieldsfirst_name
andlast_name
. - Response body:
created_time
field got deleted. - Request header:
Metadata: <key:value>
becomesClient-Metadata:<key:value>
. - Response header: Same change as request header.
- Query parameter:
language-code=<lang>-<region>
becomeslang:<lang>
andregion:<region>
You can use Nylas-Api-Version
header to control your versioning.
If you want to use 1.0, then
curl --location --request POST 'localhost:8080/?language-code=en-US' \
--header 'Nylas-API-Version: 1.0' \
--header 'Metadata: hello:world' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Zhi Qu"
}'
If you want to use 1.1, then
curl --location --request POST 'localhost:8080?region=US&lang=en' \
--header 'Nylas-API-Version: 1.1' \
--header 'Client-Metadata: hello:world' \
--header 'Content-Type: application/json' \
--data-raw '{
"first_name": "Zhi",
"last_name": "Qu"
}'
You can see both version give you the result. The middleware automatically handles versioning.