Ktor logo

Ktor

Building Asynchronous Servers and Clients in Kotlin

Ktor

Ktor Plugin Update – Navigation, Refactoring, and more!

As a tooling company, we do realise the importance of providing proper support for the languages and frameworks you use.

In the case of Ktor, we started this journey by rewriting support for IntelliJ IDEA Ultimate completely from scratch, and the first step was a new and simplified project wizard, which has already been announced.

With the 1.5.3 update, we’re improving the options in the wizard, as well as bringing new functionality!

New Project Enhancements

The Project Wizard comes with two new options:

Storing configuration

Via the Configuration in dropdown, you can define whether you want the generated project to store the server configuration as code, i.e. using the embeddedServer option, or external HOCON files.

Sample Code

By default, when adding Features (soon to be renamed to Plugins), the wizard generates some sample code for you to get you started. This is very useful for beginner, but may not be of value to more experienced users. We’ve now made this optional via the Add sample code checkbox.

Wizard

In both cases, Ktor will also generate the corresponding Run Configuration entries.

Development Enhancements

One of our goals with Ktor support in IntelliJ IDEA is to improve the overall development experience. This release
brings a bunch of new functionality in this area.

Navigation

You can now navigate to actual routes across a project. For instance, if you have a Ktor server with a specific route, and you’re referencing it from a client, you can navigate to it using the standard IntelliJ IDEA shortcuts/actions (Ctrl/Cmd+Click or Ctrl/Cmd+B), or with
Globe icon next to the URL string

Globe Icon

Much the same way, from a specific route definition, you can navigate to the usages

Find Usages

Finding routes with Search Everywhere

If you want to find a specific route in your application, you can do so using Search Everywhere (Double Shift)

Search Everywhere

Endpoint View

To see a list of all endpoints that the current module offers, you can use the Show enpoints of module

Show Endpoints

which then displays a list of endpoints in the Endpoints tool window

Endpoints tool window

From this window, you can test the call as well as open it in the HTTP editor. It will automatically detect
parameters and prompt you for these

Endpoint Execute

You can of course generate a test client request from a specific route using the Open in HTTP client option from the globe icon.

Generate Http Client

Rename Refactoring

Ktor allows you to define routes in one of two ways:

  • Using Strings
  • Using Locations (a feature that is currently being reworked)

One drawback of using strings of course is, that when it comes to renaming, this can be a bit cumbersome. Not anymore!

Much like you can now navigate to URLs and find usages, you can also perform a rename refactor, knowing that any reference to them will be renamed too. This also includes parameter names.

Rename Refactor

The IDE allows you to define the scope you want the refactoring to be applied to in case you want to limit this.

Completion

Last but certainly not least, there is also support for completion.

Completion

This is just a taster of the many features we have planned, to improve the development, testing, and deployment experience with Ktor. We’d love for you to try the plugin and let us know if you have any feedback.