Besides the common Web services support, IntelliJ IDEA provides the following facilities for developing RESTful Web services:
- Generating a sample Web service and deploying it locally
- Code completion for MIME type.
- Code inspections and quick fixes.
- REST Client tool window for testing RESTful Web services.
Generating a Sample Web Service
When you create a module for developing a RESTful WebService, you can have sample code of the server side generated.
IntelliJ IDEA creates a package with a HelloWorld class that has the following methods:
-
The
main()method that creates an instance of a local HTTP server and starts it. -
The
getClichedMessage()method that returns a cliched message. The method is supplied with the@Path,@GET, and@Producesannotations.
Use this class as an example or populate it as necessary to develop and test your RESTful Web service. To start the sample Web service, choose or press ⌃R or ⌃R⇧F10 or ⇧F10⇧⌘F11 or ⇧⌘F11^ F5, ⌃F5 or ⌃F5⇧ F10, ⇧F10 or ⇧F10. IntelliJ IDEA creates a local HTTP server, starts it, whereupon deploys and runs the Web service.
Code inspection and quick fixes
IntelliJ IDEA supports code inspections and suggests quick fixes in the following cases:
| Issue | Default Quick Fix |
|---|---|
Inconsistency between a method annotation and the method return type:
a @GET annotated method of the void return type. | Change to String. |
| Inconsistency between the class type and the type of a method within the class: a non-resource class contains resource methods. | Remove @GET, @POST, @PUT, or @DELETE
annotation from the method declaration. |
| A Root Resource Class does not contain resource methods. | Remove @Path annotation. |
Different Root Resource Classes have the same @Path annotation. | Remove @Path annotation. |
A @Consumes or a @Produces annotation uses a wrong MIME type. | Change to */*. |
Rest client tool window
Dedicated REST Client tool window supports:
- Constituting URL addresses semiautomatically from the specified Deployment point and the
@Pathannotation. - Submitting requests to the server.
- Displaying server responses in the Response tab.
- Code integration between the Java code and the contents of the REST Client window controls.
| Change in the Java code | Change in the REST Client tool window |
|---|---|
@Path annotation is updated. | The contents of the Path to resource drop-down list change. |
@Produces annotation is updated. | The contents of the Accept drop-down list change. |