Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make URI versioning optional in a nestjs REST application

NestJS URI Versioning for HTTP REST applications can be easily enabled when following the docs here.

The docs do however not explain how to make URI versioning optional.

Example:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

/api/v1/users

/api/v2/users

/api/users -> should be mapped to v1 to allow existing webhooks to keep working

Question:

How can we make the URI versioning optional in a NestJS REST application so that old versions (without any api version) keep working ?

>Solution :

Use should use the VERSION_NEUTRAL version on defaultVersion option like:

app.enableVersioning({
    type: VersioningType.URI,
    defaultVersion: [VERSION_NEUTRAL, '1', '2'],
});

https://docs.nestjs.com/techniques/versioning

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading