Skip to content

quzhi1/FiberVersioningTool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FiberVersioningTool

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/

API version 1.0 schema

Request body

{
    "name": "Zhi Qu"
}

Request header

  • Nylas-Api-Version: 1.0
  • Metadata: :

Query parameters

  • language-code=-

Response body

{
    "id": "af9c3b85-86c5-4771-b07f-22440de6d582",
    "name": "Zhi Qu",
    "created_time": 1657150876
}

Reponse header

  • Metadata: :

API version 1.1 schema

Request body

{
    "first_name": "Zhi",
    "last_name": "Qu"
}

Request header

  • Nylas-Api-Version: 1.0
  • Client-Metadata: hello:world

Query parameters

  • lang:
  • region:

Response body

{
    "id": "c497668b-89c7-48cd-b659-867f3287b023",
    "name": "Zhi Qu"
}

Reponse header

  • Client-Metadata: hello:world

How to play with it

Version 1.1 is not backward compatible with version 1.0. Specifically:

  1. Request body: name field splitted into two fields first_name and last_name.
  2. Response body: created_time field got deleted.
  3. Request header: Metadata: <key:value> becomes Client-Metadata:<key:value>.
  4. Response header: Same change as request header.
  5. Query parameter: language-code=<lang>-<region> becomes lang:<lang> and region:<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.

About

My proof of concept of versioning framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published