I usually post about HTTP stuff on Twitter - you can follow me there:

This is a comprehensive guide to using Apache HttpClient 4 – from starting out to advanced configuration and best practices.

1. HttpClient Basics

Learn the basics of sending a Request, receiving and interpreting the Response and configure the Client for basic usage.


2. Advanced Usage

Go into more advanced usecases of configuring the client with SSL, Custom Cookies, different types of Requests, etc.

The implementation of all these examples and code snippets can be found in my github project – this is an Eclipse based project, so it should be easy to import and run as it is.

I usually post about HTTP stuff on Twitter - you can follow me there:

  • Fosho Law

    Would you still suggest using HttpClient 4 over Spring’s RestTemplate or Feign? If so, could you elaborate why?

    • Hey Fosho – HttpClient gives you a good base. RestTemplate is a bit higher level but doesn’t have the full flexibility of the HttpClient. And I haven’t used Feign yet (it’s on my list to explore).
      Generally speaking, it’s not that I recommend HttpCient – but it’s certainly very mature and highly flexible, which most other clients still aren’t).
      My suggestion is – if you prefer the syntax of another client, so a quick spike to try it out. You may find that it handles everything you need perfectly fine. And if you do need more control – then the HttpClient is a good way to go.
      Hope that helps. Cheers,

      • Fosho Law

        Thanks for the reply. Always appreciate when blog authors actually reply 🙂

        Can you briefly name a few things that HttpClient gives you more control of than RestTemplate? (I’m curious because I usually use RestTemplate)

        • Yeah, me to – that’s why I do it 🙂
          So, there are many small things – mainly because these operate at different abstraction levels. And of course one of the implementations that RestTemplate eventually uses is based on the HttpClient.
          So, if you’re doing things that are more non-standard – such as sending a DELETE request with a body, fine-tuning the connection pool, configuring keey-alives, keeping track of sessions, etc – essentially anything that’s more low level HTTP – then you’re going to have an easier working with the HttpClient.
          That’s not to say that all of these things are impossible with the template, just harder.
          If you’re just interacting with a REST API – then you might be OK using the template.
          Hope that gives you a better idea of what I’m referring to.

          • Fosho Law

            I see! Thanks for the insightful reply!