当前位置:网站首页>[test platform development] 20. Complete the function of sending interface request on the edit page

[test platform development] 20. Complete the function of sending interface request on the edit page

2022-07-23 14:51:00 Test notes of biting and crying apples

be based on springboot+vue Test platform of ( Hand training program ) Development continues to update .

Today, I finally reconstructed all the functions I have done .

The front end has been slightly adjusted , It's a control that adds and deletes parameters dynamically , I was 3 individual tab Reuse a component , Later, I found some problems , Finally, I decided to write separately .

Another focus today is to redo the back-end function of editing page sending interface request . This function existed before refactoring , But now I think the previous ones are not compatible enough .

Because I have recently accessed some of the opening of Feishu in my work API, It is found that the input parameters of some interfaces are composed , such as post In request , Existing query parameters , There is also a request body .

So I combed it again , Try to support various parameter combinations :

  • Without any parameters
  • Only param Query parameters
  • Only rest Path parameter
  • Only body Parameters
  • meanwhile param + body
  • meanwhile rest + body

If you ask for a method , For the time being, we should support get And post this 2 The most common . Last , I've branched out all kinds of judgments , Make sure there is nothing wrong .

Function realization

Next, record the implementation of the function . The idea is simple :

  • Acquisition and processing of some necessary parameters
  • Judgment of different request methods
  • Further judge different parameter combinations , To send http Interface processing .

With http The client is hutool Framework of the , The code is located here in the project ,93 Line back .

First , The main method deals with some necessary input parameter information , such as method、header、 And get the parameters in the form .

Next, go to the judgment of the request method , Then further judge the various types of parameters submitted by the front end , Here I took it out and wrote 2 A way to judge empty .

With get Methods as an example , Now I can judge who the parameters actually submitted are .

Determine the parameter type , It can be dealt with pertinently , The most troublesome thing here is rest Processing of path parameters , The path parameters submitted by my front end are wrapped in curly braces {name}, So be right url Deal with it again .

After splicing , You can directly initiate the request .

Here Be careful Yes. , stay hutool Of http The client , I participate in the use body() I will put form() The parameter of , So when processing the combination of request body parameters , Only query parameters or path parameters , All processing requests url On . such as , This is to deal with param+body The combination of , Manual handle param Parameter splicing to url On .

Nothing else is special , stay post I don't think it's necessary to support so many situations , So it is only compatible 3 In this case .

At present, it is only an appeal of function realization , There is also a lack of exception handling , Follow up slowly . Next, we will continue to develop new functions , In the process, I will also take some changes I recorded bug .

The latest code at the front and back ends has been updated to the branch , If you also want to start children's shoes, you can reply on the official account 【 Test platform 】, You can get the address and development records of a series of articles .

原网站

版权声明
本文为[Test notes of biting and crying apples]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207230901170713.html