Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move /shorten to /api/shorten_url #21808

Merged
merged 5 commits into from Aug 9, 2018
Merged

Conversation

nreese
Copy link
Contributor

@nreese nreese commented Aug 8, 2018

prerequisite for migrating share top nav to EUI and react. The reason for such a big PR is that kfetch expects the response to be JSON and /shorten returns a string.

This PR

  1. de-angularizes url_shortener
  2. creates a new API endpoint /api/shorten_url that is a replacement for the existing endpoint /shorten. /shorten does not return JSON and is not under /api.
  3. Marks /shorten as deprecated so it can be removed in 7.0

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@stacey-gammon
Copy link
Contributor

Nice! Couple things:

Can you add a section for this API under docs/api in asciidoc? Can you also create an issue and mark it as a 7.0 blocker to update the 7.0 breaking changes docs to include the removal of this API?

@epixa - what's the standard way to highlight a deprecation in the rest API? No documentation around this API currently exists in asciidoc. I think that's just because we don't have a lot of documentation, not for any other reason. So there isn't an existing /shorten API documentation for where to put the deprecation warning. Maybe there is some other place for it? Above and beyond the warning being logged to the server.

Copy link
Contributor

@stacey-gammon stacey-gammon left a comment

Choose a reason for hiding this comment

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

Aside from the one comment, code lgtm. Pulled down and did very basic test to create and goto a short url. Did not check the original API but looks like we have test coverage of that.

const shortUrlLookup = shortUrlLookupProvider(server);

server.route(createGotoRoute({ server, config, handleShortUrlError, shortUrlAssertValid, shortUrlLookup }));
server.route(createShortenUrlRoute({ handleShortUrlError, shortUrlAssertValid, shortUrlLookup }));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why pass shortUrlAssertValid in as a parameter rather than import directly from those files? Same with handleShortUrlError.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no real reason. I was passing in shortUrlLookup so just figured to pass in everything to stay consistent.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you ever see these functions needing to handle different implementations of those two parameters? If not, I think it'd be more consistent and less complex if you imported and called directly. The fewer function parameters you can get away with, the simpler the code (and easier to test).

@nreese
Copy link
Contributor Author

nreese commented Aug 9, 2018

issue to update breaking changes log has been created #21836

@epixa
Copy link
Contributor

epixa commented Aug 9, 2018

We should do the breaking change doc in the same PR that actually removes the existing behavior in master. That PR can be thrown up as soon as this is merged rather than having a lingering blocker for 7.0.

what's the standard way to highlight a deprecation in the rest API? No documentation around this API currently exists in asciidoc. I think that's just because we don't have a lot of documentation, not for any other reason. So there isn't an existing /shorten API documentation for where to put the deprecation warning. Maybe there is some other place for it? Above and beyond the warning being logged to the server.

There is no such standard. Without specific documentation for this endpoint, we should just mention the change in the release notes and make sure there's an appropriately documented breaking change in master.

Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

Couple notes, will pull down and try running in a bit

@@ -144,9 +143,12 @@ app.directive('share', function (Private) {
this.urlFlags.shortSnapshot = !this.urlFlags.shortSnapshot;

if (this.urlFlags.shortSnapshot) {
urlShortener.shortenUrl(this.urls.snapshot)
shortenUrl(this.urls.snapshot)
Copy link
Contributor

Choose a reason for hiding this comment

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

I kind of thought we decided to cast es6 promises to angular promises, rather than calling $scope.$apply()?

Promise.resolve(shortenUrl(this.urls.snapshot))
  .then(shortUrl => {
    this.urls.shortSnapshot = shortUrl;
  })

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we could but it will not matter in the next couple of days since the next step for EUI and rectifying the share top nav is to rip this directive out replace with a react component. This is just temporary.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just for other efforts similar to this, if we can avoid using $scope.$apply() we should.

});
}).catch((response) => {
notify.error(response);
return kfetch({ method: 'POST', 'pathname': '/api/shorten_url', body }).then((resp) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

async/await?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if that is preferred. Figured with the catch block this was just as easy.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think async/await is more than just easy, I think it's also easier to read and more aligned with non-async code, so I would say I prefer it regardless.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@stacey-gammon stacey-gammon left a comment

Choose a reason for hiding this comment

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

LGTM. (did not pull down & test latest changes) docs look good, thanks!

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@nreese nreese merged commit 803a3f1 into elastic:master Aug 9, 2018
nreese added a commit to nreese/kibana that referenced this pull request Aug 9, 2018
* Move /shorten to /api/shorten_url

* better API test assertions

* add API documenation

* use async await

* import dependencies instead of pass in
nreese added a commit that referenced this pull request Aug 9, 2018
* Move /shorten to /api/shorten_url

* better API test assertions

* add API documenation

* use async await

* import dependencies instead of pass in
epixa added a commit to epixa/kibana that referenced this pull request Aug 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants