Code Monkey home page Code Monkey logo

Comments (6)

vortec avatar vortec commented on May 9, 2024

Due the nature of semantic versioning, where every bugfix means a new patch version, you will likely end up with more distinct versions than currently.
This means that developers must delete old endpoints from time to time. To make this task easier, I think it's essential to have hug compile a list of all existing versions and their corresponding endpoints.

Also you could make the usage even more explicit (and save some keystrokes) by introducing a semver type:

@hug.get(versions=hug.semver(3, 2))
def endpoint():
   pass

from hug.

nugend avatar nugend commented on May 9, 2024

This is something you would literally never want to use if your API faced the public Internet, right?

from hug.

vortec avatar vortec commented on May 9, 2024

@nugend could you elaborate on that please?

from hug.

nugend avatar nugend commented on May 9, 2024

Because you can't retire parts of the API or change functionality if you later discover that there is a bug or security issue and still maintain the semantic guarantee implied by the version. Like, maybe you could get away with the minor version bumps preventing a new endpoint from being seen, but unlike distributed code, it's you, the API provider's risk if you keep the old version alive, not the person using the software.

from hug.

timothycrosley avatar timothycrosley commented on May 9, 2024

@nugend, that's correct, however I think the vision here is more to allow a 1:1 mapping between your library code version and API version if you choose. Without any guarantee that 1.2.x version is supported. For instance you could choose to only have special behavior for > 1.4.x and keep the old behavior the same for < 1.4.x, right now that would mean you have to release a new version of the API version (say 2) when which clearly would separate you from your semantic version. I don't think there is any expectation that people would keep a large number of APIs supported at a single time, no more then say 2-3, this just would provide them a mechanism to keep the versions they do support in-sync with their semantic version numbers for APIs that are exposed in both forms.

from hug.

drewpc avatar drewpc commented on May 9, 2024

+1 for this feature.

I'd recommend using this library. You can define Spec and Version objects. This would be a great way to separate the what versions a specific API function applies to (Spec) and the version that the user is requesting through the API call (Version). Here's an example from their site:

>>> s = Spec('>=0.1.1')  # At least 0.1.1
>>> s.match(Version('0.1.1'))
True
>>> s.match(Version('0.1.1-alpha1'))  # pre-release satisfy version spec
True
>>> s.match(Version('0.1.0'))
False

>>> s = Spec('==0.1.1')
>>> Version('0.1.1-alpha1') in s
True
>>> Version('0.1.2') in s
False

So, the Hug API might look like this:

@hug.get(versions=Spec('>=0.1.1'))
def endpoint():
   pass

And then the version number found in an HTTP URL, CLI argument, or local variable would be an instance of the Version type. The Hug router would compare the Version instance to the Spec instance to see if it's compatible.

I can work on a PR for this feature, but it'll be in a few weeks from now.

from hug.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.