Skip to content

Add support for API versioning#52

Open
mikkoseppa wants to merge 3 commits intoVincit:masterfrom
mikkoseppa:ms-add-support-for-api-versioning
Open

Add support for API versioning#52
mikkoseppa wants to merge 3 commits intoVincit:masterfrom
mikkoseppa:ms-add-support-for-api-versioning

Conversation

@mikkoseppa
Copy link

  • Refactor Route to support multiple handlers and api versioning.
  • Add HeaderApiVersioning and RouteApiVersioning features.
  • Refactor Router to forward apiVersioningConfig from Router's config to Route.
  • Also resolve feature name in Router to the actual versioning feature.
  • Add tests for Router and both versioning features.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 95.887% when pulling 9303cd9 on mikkoseppa:ms-add-support-for-api-versioning into c671411 on Vincit:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 95.887% when pulling 9303cd9 on mikkoseppa:ms-add-support-for-api-versioning into c671411 on Vincit:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 95.887% when pulling 9303cd9 on mikkoseppa:ms-add-support-for-api-versioning into c671411 on Vincit:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 95.887% when pulling 9303cd9 on mikkoseppa:ms-add-support-for-api-versioning into c671411 on Vincit:master.

@coveralls
Copy link

coveralls commented Oct 9, 2018

Coverage Status

Coverage decreased (-36.7%) to 59.283% when pulling 706d4dd on mikkoseppa:ms-add-support-for-api-versioning into c671411 on Vincit:master.

@mikkoseppa mikkoseppa force-pushed the ms-add-support-for-api-versioning branch 2 times, most recently from f8ef394 to 300c279 Compare October 11, 2018 07:09
@elhigu
Copy link

elhigu commented Oct 11, 2018

We could remove older than 6 node versions from travis

TypeError: availableApiVersions.includes is not a function

* @param {Object} req Epxress request object
* @returns {number} Api version
*/
findApiVersionFromRequest: function(req) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this function would get actually handler (req) => { return apiVersionOrUndefined; } callback as parameter, it could work for any kind of method for fetching API version from request so we wouldn't have to hardcode any parameter / header names.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't quite get the point. Could you give me a small code example how this would work?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in configuration could be like this

    config = {
      parseCallback: (req) => { 
        let headerString = req.headers['accept'];
        let pattern = 'application\/vnd.someapplication\.v(\\d+)\\+[A-Za-z]+';
        let results = header.match(new RegExp(pattern));
        return results ? parseInt(results) : undefined;
    };

That way one could decide with complete freedom how API version number is extracted anywhere from request.

Copy link
Author

@mikkoseppa mikkoseppa Oct 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR updated to support generateRoutePathHandler and findApiVersionHandler in config.


it('should be able to register a versioned handled for two different versions', function () {
router[method]('/some/path')
.public()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All api version handlers share the same authentication code? Would be good to have also tests, which uses default authenticator and custom authentication handlers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added apiVersioning+auth and apiVersioning+middleware tests to PR.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still couldn't find the case where handlers would be called with defaultAuthHandler included... all the routes seemed having .public() at start, which removes the default handler.

@mikkoseppa mikkoseppa force-pushed the ms-add-support-for-api-versioning branch 2 times, most recently from 0a6419f to 6b4b8d1 Compare October 12, 2018 09:48
- Refactor Route to support multiple handlers and api versioning.
- Add HeaderApiVersioning and RouteApiVersioning features.
- Refactor Router to forward apiVersioningConfig from Router's config to Route.
- Also resolve feature name in Router to the actual versioning feature.
- Add tests for Router and both versioning features.
@mikkoseppa mikkoseppa force-pushed the ms-add-support-for-api-versioning branch from 6b4b8d1 to 76770fb Compare October 12, 2018 10:07
… request but handler is not found.

- Add fallback functionality to Route findHandler_ function.
- Add tests.
@elhigu
Copy link

elhigu commented Nov 6, 2018

Could you still drop node .12 from .travis.yml file to make tests pass?

});
});

describe.only('API versioning', function() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, .only should be dropped too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants