aspnet-api-versioning | add service API versioning to ASP.NET Web API | SQL Database library

 by   microsoft C# Version: v5.0.0 License: MIT

kandi X-RAY | aspnet-api-versioning Summary

kandi X-RAY | aspnet-api-versioning Summary

aspnet-api-versioning is a C# library typically used in Database, SQL Database, Swagger applications. aspnet-api-versioning has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

Provides a set of libraries which add service API versioning to ASP.NET Web API, OData with ASP.NET Web API, and ASP.NET Core.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              aspnet-api-versioning has a medium active ecosystem.
              It has 2038 star(s) with 589 fork(s). There are 116 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 34 open issues and 566 have been closed. On average issues are closed in 108 days. There are 2 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of aspnet-api-versioning is v5.0.0

            kandi-Quality Quality

              aspnet-api-versioning has 0 bugs and 0 code smells.

            kandi-Security Security

              aspnet-api-versioning has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              aspnet-api-versioning code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              aspnet-api-versioning is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              aspnet-api-versioning releases are available to install and integrate.
              aspnet-api-versioning saves you 3 person hours of effort in developing the same functionality from scratch.
              It has 10 lines of code, 0 functions and 1019 files.
              It has low code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of aspnet-api-versioning
            Get all kandi verified functions for this library.

            aspnet-api-versioning Key Features

            No Key Features are available at this moment for aspnet-api-versioning.

            aspnet-api-versioning Examples and Code Snippets

            No Code Snippets are available at this moment for aspnet-api-versioning.

            Community Discussions

            QUESTION

            Get ASP.NET Core API version programmatically in integration test
            Asked 2021-Oct-21 at 13:53

            I'm using ASP.NET Core with the ASP.NET API Versioning service.

            When I register the service, I use this format:

            ...

            ANSWER

            Answered 2021-Oct-21 at 13:53

            This can be retrieved from the container like so:

            Source https://stackoverflow.com/questions/69585346

            QUESTION

            ASP.NET 5 Web API CreatedAtAction: POST returns 500
            Asked 2021-Jul-15 at 20:30

            I have a simple ASP.NET 5 Web API with a controller for uploading/downloading files, like:

            ...

            ANSWER

            Answered 2021-Jul-15 at 20:30

            When using overload CreatedAtAction(string, object), param object is not route parameters as you assume, but body content. Hence, code is looking for a route to GET api/contents which doesn't exists.

            You'll need to use overload CreatedAtAction(string, object, object) where param #2 contains route params, and param #3 contains body content. So in your case, return CreatedAtAction(nameof(DownloadContent), new { id = id }, null); will work.

            I was able to reproduce your issue with this controller and Postman:

            Source https://stackoverflow.com/questions/68397822

            QUESTION

            API Versioning in .NET Core - AssumeDefaultVersionWhenUnspecified
            Asked 2021-Jun-29 at 17:40

            I'm looking into adding versioning to an existing API we have. We are embedding the version in the URL.

            The requirement for the versioning is that it should be easy to add a new version, but not everything changes and we don't want to go through all controllers and add new version attributes when we get a new version. Is there any way to tell Microsoft.AspNetCore.Mvc.Versioning that a particular method should be available regardless of versions?

            I have tried decorating my method with both with the version:apiVersion and with just a basic route.

            ...

            ANSWER

            Answered 2021-Jun-29 at 17:40

            Setting AssumeDefaultVersionWhenUnspecified = true is a highly abused feature. This is only meant to facilitate backward compatibility. Once you opt into API Versioning, all API controllers have some implicit or explicit API version. Assuming a version provides a mechanism to handle the "original", unnamed version that would otherwise break existing clients that don't know to include an API version in requests.

            "Is there any way to tell Microsoft.AspNetCore.Mvc.Versioning that a particular method should be available regardless of versions?"

            Yes, but I'm not entirely sure that is what you're looking for. An API can be version-neutral, which means it will accept any and all API versions, including none at all. This is useful for certain types of APIs such as a /ping health check or DELETE, which typically do not change over time. Such an API can be decorated with [ApiVersionNeutral]. This can be for all APIs on a controller or a specific action. Note that once you choose this path, "there can be only one."

            There is not a complete picture of your setup. It appears that you are adding API versioning to an existing set of APIs. One of the primary purposes of DefaultApiVersion is to set what the default API version should be when no other information is available. If you applied no API versions whatsoever - for example, using attributes, then this would be the implicit API version of all APIs. This prevents you from having to retrofit all of your existing controllers and code. What's less obvious is that once you apply any explicit API version, then the implicit rule is ignored. This ensures that implicit versions can be sunset. The default version often does not matter. It's simply a way for you to indicate what the initial API version originally was. It's most relevant when grandfathering in existing APIs.

            Given your configuration:

            Source https://stackoverflow.com/questions/68174963

            QUESTION

            ASP.NET Core API Versioning - Same controller for all versions
            Asked 2021-Mar-23 at 19:08

            I have an ASP.NET Core 3.1 API and I am introducing a new version for one of my controllers. I am using the Microsoft.AspNetCore.Mvc.Versioning NuGet package and I have set the new version to be the default version. All my other controllers should work with both the old version (1.0) and the new version (1.1).

            For example:

            ...

            ANSWER

            Answered 2021-Mar-23 at 19:08

            Q: Do I really have to add all versions to all controllers?

            A: Yes. API versions are discrete. A client should get exactly what they ask for and an appropriate error response if the server cannot satisfy the request.

            Q: Is there a better/correct way of handling this?

            A: There are several possible options. A better or more correct way of handling things is highly subjective. There are numerous factors and the final decision may simply come down to preference.

            A common misconception is that API Versioning uses attributes. It really doesn't care about attributes, it's just one possibility and one that tends to resonate with developers as metadata. You have the choice to use out-of-the-box attributes, custom attributes, out-of-the-box conventions, or your own custom conventions.

            The choice of how to apply the version metadata is typically of preference and practical management. A common scenario is to organize controllers in folders by API version. In several .NET languages, the folder name translates to part or all of the corresponding namespace. This arrangement is common enough that there is an out-of-the-box VersionByNamespaceConvention for it. For details, see the documentation. The By Namespace Sample also demonstrates how to up such a project end-to-end.

            API version-neutral means that an API takes any and all versions, including none at all. It can mean you don't care about the API version or that you accept a whole range that you'll deal with yourself. It is really only meant to be used with APIs that never change over time. For example, a HTTP DELETE operation typically does not change over time or across versions.

            It's not 100% clear what you mean by:

            "If I do not add the [ApiVersion] attribute, it defaults to the new 1.1 version and 1.0 no longer works."

            There are no defaults per se. This statement seems to imply that you have set the AssumeDefaultVersionWhenUnspecified option to true. You should not do that unless you have a very good reason to do so. That is probably one of the most abused features of API Versioning. A client must know the version it is asking for. Allowing a client to not specify a version and having things transition from 1.0 to 1.1 can break the client. The server can make no assumption that it won't. This feature was meant to grandfather in existing services that didn't previously have an explicit version defined. That scenario only exists when API Versioning is first enabled. As stated above, all controllers must have one or more discrete API versions, but the original set of APIs didn't have it explicitly defined. If this feature didn't exist, then the baseline set of clients that didn't know about an API version would break.

            Source https://stackoverflow.com/questions/66747832

            QUESTION

            CreatedAtAction throws InvalidOperationException when using API Versioning
            Asked 2020-Aug-14 at 17:47

            EDIT: here's a repo which simulates the error.

            I'm building an API using ASP.NET Core together with ApiVersioning. My controllers are annotated with [Route("api/v{version:apiVersion/[controller] and on my POST actions I'm returning the location of the created resource:

            ...

            ANSWER

            Answered 2020-Aug-12 at 20:02

            It's solved, I'm leaving it here for future generations.

            When calling CreatedAtAction, you must inform the version of the action you want to call. While this may be obvious, there's an exact way to do so:

            Either capture the current version and pass it back:

            Source https://stackoverflow.com/questions/63382832

            QUESTION

            Change casing of JSON properties between api versions using Microsoft's ASP.NET API Versioning for Web API 2 and ODATA?
            Asked 2020-Jun-01 at 13:50

            I am introducing API versioning to an existing API. The existing JSON uses Pascal casing for its property names e.g. "FooBar": "foo". For v2 of the API, I would like to use the common camel casing, "fooBar": "foo". I need to keep v1 Pascal casing so that it does not impact any client that is already pulling that version of the API.

            My project is

            • ASP.NET MVC 5.2.7
            • ASP.NET WEB API 5.2.7
            • ASP.NET ODATA 7.4.0
            • ASP.NET WEB API Versioning 4.0.0

            My configuration is as follows

            ...

            ANSWER

            Answered 2020-Jun-01 at 13:50

            Using the OData Model Configurations approach described here first add a class that derives from IModelConfiguration to your project.

            Something like this:

            Source https://stackoverflow.com/questions/62129610

            QUESTION

            Add header to response if requested version is deprecated
            Asked 2020-Feb-26 at 16:40

            I would like to add a custom header to my service's response if a deprecated version is requested.

            I already have URL-based versioning set up using Microsoft.AspNetCore.Mvc.Versioning, and I additionally have an existing custom ActionFilter class that can write custom headers into the response. I can also get the version requested by the client using context.HttpContext.GetRequestedApiVersion() inside my ActionFilter's definition for OnActionExecuted(ActionExecutedContext context).

            However, I'm not sure how I can check whether the requested version is a deprecated version or not from my custom ActionFilter. The documentation on deprecating a service version does not answer this question and I can't find the answer among any of the rest of the documentation on github.

            My controller class is annotated as follows:

            ...

            ANSWER

            Answered 2020-Feb-26 at 16:40

            From the incoming request you will see what the URL is, and therefore you can determine which controller it will be mapped to. Controllers are classes, and the deprecated ones are marked with the [ApiVersion(Deprecated = true)] attribute. So you can grab the controller, and with reflection you can check its attributes and see if it's deprecated. Documentation here

            Source https://stackoverflow.com/questions/60418395

            QUESTION

            API versioning via EntityFramework Core at repository level?
            Asked 2020-Feb-21 at 17:39

            I have GetAllStudents() in 2 versions (GetAllStudents() and GetAllStudentsV2()).

            How to manage versioning in repositories via EntityFramework Core? just like what we have as ASP.NET API Versioning

            Can we have versioning at the repository level? (EF/Dapper/...)

            ...

            ANSWER

            Answered 2020-Feb-21 at 17:37

            You generally do not version EF because - you still have only one database anyway.

            You version the API because it is a "public interface", not an implementation detail. But the db is internal and IS an implementation detail.

            Which is why most people will not expose EF objects via an API - they will project them to API objects (which is a way you can handle changes in the db when versioning).

            Source https://stackoverflow.com/questions/60343672

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install aspnet-api-versioning

            You can download it from GitHub.

            Support

            Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) secure@microsoft.com. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the Security TechCenter.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/microsoft/aspnet-api-versioning.git

          • CLI

            gh repo clone microsoft/aspnet-api-versioning

          • sshUrl

            git@github.com:microsoft/aspnet-api-versioning.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link