I forget who planted Postman. Postman has been my preferred tool for interface testing for a long time. A friend of mine used RestfulToolkit in IDEA with me before, but I never had the chance to experience it. It works fine in some scenarios (scenarios that don’t require certification), so share it with your friends.

1. RestfulToolkit

RESTful Toolkit is a set of tools for RESTful service development. It provides the following functions:

  1. Jump directly to the corresponding method definition based on the URL (Ctrl \ or Ctrl Alt N);
  2. Provides a Services Tree display window;
  3. A simple HTTP request tool;
  4. Useful functionality has been added to the request method: copy generates the URL; , copy method parameters…
  5. Other features: Add Convert to JSON function on Java class, format JSON data (Windows: Ctrl + Enter; Mac: Command + Enter).

It supports Spring architecture (Spring MVC/Spring Boot 1.x,2.x); Support JAX – RS; Support for Java and Kotlin languages.

2. Install

Select File->Plugins in IDEA and then search for RestfulToolkit as follows:

Then click install button and restart IDEA after installation:

Use 3.

Create a project and on the right side of the project you will see Rest Services options as follows:

Click on this TAB and you are ready for RESTful interface testing.

Songo wrote four test interfaces. Take a look:

@RestController
public class BookController {
    @PostMapping("/book")
    public RespBean addBook(Book book) {
        System.out.println(book);
        return RespBean.ok("Added successfully");
    }

    @GetMapping("/book/{id}")
    public Book getBookById(@PathVariable Integer id) {
        Book book = new Book();
        book.setId(id);
        return book;
    }

    @PutMapping("/book")
    public RespBean updateBook(@RequestBody Book book) {
        return RespBean.ok("Update successful");
    }

    @DeleteMapping("/book")
    public RespBean deleteBookById(Integer id) {
        return RespBean.ok("Deleted successfully"); }}Copy the code

These four excuses basically cover our daily common ways to start a project, let’s take a look at the right:

As you can see, the four test interfaces are displayed in the RestfulToolkit after the project is successfully started:

In addition, different interfaces have corresponding default parameters, such as update interface, the parameter is JSON format, here will be automatically listed:

The developer only needs to fill in the specific parameter values according to the actual situation.

The test is successful and the results are as follows:

The RestfulToolkit has a function that you can click on an interface to jump to the corresponding method definition as follows:

Select the interface, right-click it, and have two options:

  • Copy Full Url: Copies the Full Url.
  • Jump to Source: Jump to the code defined by the interface.

In addition to this, RestfulToolkit can help you quickly convert JSON from a class. This is a good way to use postman when writing your own JSON is too slow. Here’s how:

Select the class name, right click, and there are two options at the top, as follows:

  • Convert to JSON (Compressed) : Generate a Compressed JSON, actually a line of JSON.
  • Convert to JSON: Generates a formatted JSON.

4. An aside

What about Cookie+Session authentication using RestfulToolkit? In fact, a qualified RESTful interface is itself stateless. Since it is stateless, there is no need for cookies for authentication. Each request carries its own token, and RESTful Toolkit supports modifying the request header anyway.

However, if your project is based on Cookie + Session authentication, I still recommend using Postman for interface testing, because it is more professional. Alternatively, you can try the Http Client tool that comes with IDEA.

After the 2020 version of IDEA, you can use Restful Tools.