One of the biggest things that happened in technology in 2020 was to write an HTTP client tool and push open source, which currently has nearly 400 stars on Github. Maybe 400 stars is totally insignificant for all the tech heads, but it’s not easy for me, who is still Iron Han. In the whole process, I experienced the boring source code, code design entanglements and open source when the joy of completion. Now, let’s talk about it in detail.

Project address: github.com/LianjiaTech…

origin

I believe that many friends like me, have a certain “obsessive compulsive” code. When you encounter code that isn’t good enough to implement or convenient enough to use, you want to wrap it up. This can not only exercise their abstract design ability, but also significantly improve the efficiency of research and development, killing two birds with one stone. Back in April 2019, our system was a Spring-Boot framework project with a lot of HTTP interface calls, but they were made directly from business methods like HttpUtil. This approach not only loses the possibility of flexible extension at the framework level, but also completely deviates from object-oriented design principles. As someone who has always had a compulsion to code, I couldn’t help it.

Of course, it’s not enough to have an idea, it’s more important to put it into practice. The first thing I did was figure out what I wanted to achieve in the end. It’s called “start with the end in mind”. Here, I associate myBatis framework to execute SQL directly through the interface. In fact, both executing SQL and making HTTP requests are essentially a form of data interaction, so my ultimate goal is to enable Spring-Boot projects to make HTTP requests through the interface. Then the second thing is the code implementation, I did not come up directly stroking the code, but first to investigate the relevant open source implementation, after all, standing on the shoulders of giants to see further. After a bit of research, I came up with two projects that I considered, the first being Feign and Retrofit, both of which support HTTP requests through interfaces. Considering that Feign was a consumer-side invocation framework in Spring Cloud, and our project was not a Spring Cloud project at the time, we abandoned Feign because we did not want to introduce Spring Cloud-related dependencies. Retrofit is an HTTP client tool wrapped around OKHTTP, which is also widely used, so Retrofit was chosen.

However, the ideal is full, the reality is very skinny. Retrofit doesn’t officially provide a starter for quick integration with spring-Boot projects, which forced me to integrate it with spring-Boot myself. In fact, the first version I did was an integration, and it was almost usable. Had the story stopped there, I would have managed to scrape a 60 or even fail. Instead of settling for code, we should pursue perfection. Therefore, I came up with a bolder idea to do an open source project to peel off business code and achieve a more complete and elegant package.

Open source

In every programmer’s mind, it’s cool to write your own open source project, and all I wanted to do was make it happen. But when it comes to doing it, I find that things are much more complicated than I imagined. Because open source projects are ultimately meant to be used by others, I am more stringent about the design and quality of my code. At the time, I had to admit that I didn’t know enough about the source code of the relevant frameworks, in other words, I didn’t have the skills to write an open source project. At this time, I want to do things is the first dead knock relevant source code. After more than 3 months, I finally understood all the core source code of retrofit, Spring and Mybatis frameworks. Read the source code students should know that the process of looking at the source code with some “suffering”, but seriously after the harvest will be great.

Once the preparation is complete, the code design and implementation begins in earnest. At this point, before gnawing on the effect of the source code is clearly reflected, WHEN I write code will naturally associate with the excellent implementation of open source framework, and then learn from it. This is a very abstract feeling, I believe that students have gnawn source code experience. It took me about two months to code, and I was so excited about the whole process that I remember going to sleep thinking about how to code it. Because these jobs are carried out in spare time, so during the past half year, my spare time life has obviously become very full, now looking back, it is really tired but very fruitful.

When everything was ready, it was time for the actual test. We replaced the HTTP calls of two Java projects online and went online directly through the self-test. After the launch, the results were good without any exceptions. Later, the project was officially applied for open source. The whole process was quite lengthy, and it took about 4 months. Finally, it was approved in April 2020. I remember that it was Qingming Festival and I officially launched my first open source project on Github. Unconsciously completed the goal, very gratified.

The star

In the next two months, I mainly did some iterative optimization of features, and the number of stars on Github was still very low. In June, I was ready to write version 2.0. The reason I wrote 2.0 so quickly was not because we were bad at 1.0, but because there was a shift in my thinking during that time. When I was writing 1.0, I was thinking about what features the project should support and what frameworks it should be compatible with, which was definitely something I should be thinking about, but it seemed like a deviation from the direction and reality. I made the implementation complex only to support requirements that might not exist. Therefore, in 2.0 design, I made a lot of simplification, keeping only the most important and core features, I feel that users will be more interested and feel more secure if they can understand your design immediately. In the end, I spent two full days documenting 2.0, which was an incredible thing.

Since I was already writing technical articles at this point, I posted an article on Nuggets that introduced the use of open source projects. In order to catch the eye, I chose a very spooky title “The Most elegant HTTP client tool under the Spring-Boot Project, Just use it!” . Unexpectedly, it went viral and was immediately listed on the top recommendation of the day and brought me more than 30 stars. This is usually “small transparent” for me, is really unexpected. Later, many technical public accounts also reprinted my open source projects, such as Programmer DD, HelloGithub, Java Friends, SpringForAll community and so on. As of December 12, the project has garnered nearly 400 stars on Github.

harvest

For me, after finishing the whole open source project, I have not only gained more growth in technology, but also gained confidence. In daily work, I am not afraid of more complex business, and I want to make more achievements in technology. Recently, I listened to Luo Pang’s 2019 New Year’s Eve speech again. I was deeply impressed by two words in it, one is “people of my generation” and the other is “people who work”. “My generation” is a kind of confidence and pride, “doer” is a down-to-earth attitude. 2020 will soon pass, 2021 is coming, continue to come!

Denver annual essay | 2020 technical way with me The campaign is under way…

Welcome to my open source project: a lightweight HTTP invocation framework for SpringBoot