title: Adding query parameters to URL on HTTP request
body: <p>I was looking at a few post regrading query parameters in my URL and I couldn't quite find what I was looking for.</p>
  <p>So far the external API I am fetching data from requires a specific I will call in this case &quot;tag&quot; parameter when making HTTP request in the browser.</p>
  <p>Here is my Post model with a tag defined as a field</p>
  <pre><code>package com.example.blog.post;
  
  import javax.persistence.*;
  
  @Entity
  @Table(name = &quot;post&quot;)
  public class Post{
  
      @Id
      @GeneratedValue
      private Long id;
  
  
      private String tag;
  
      public Post() {
  
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public Long getId() {
  
          return id;
      }
  
      public String getTag() {
          return tag;
      }
  }
  </code></pre>
  <p>And here is my controller class and the &quot;getPosts()&quot; method is where I am fetching the external data but it requires a tag parameter (query parameter) in order to complete the response. How do I incorporate the &quot;tag&quot; query parameter in this case?</p>
  <pre><code>package com.example.blog.post;
  
  import org.springframework.web.bind.annotation.*;
  import java.util.*;
  import org.springframework.http.*;
  import org.springframework.web.client.RestTemplate;
  import com.example.blog.HttpRequest;
  
  @RestController
  @RequestMapping
  public class PostController {
  
      private PostRepository postRepository;
  
      private RestTemplate restTemplate;
  
  //    @GetMapping(&quot;/api/ping&quot;)
  //    public ResponseEntity&lt;?&gt; ping(){
  //        String res = request.body();
  //        return new ResponseEntity&lt;&gt;(res,HttpStatus.OK);
  //    }
  
  
  
      @GetMapping(&quot;/api/posts&quot;)
      public ResponseEntity&lt;?&gt; getPosts(@RequestParam(value=&quot;tag&quot;) String tag){
          try{
              HttpRequest request = HttpRequest.get(&quot;https://api.blogs.io/blog/posts&quot;).connectTimeout(12000);
              String res = request.body();
              return new ResponseEntity&lt;&gt;(res,HttpStatus.OK);
          }catch (Exception e){
              e.printStackTrace();
              return new ResponseEntity&lt;&gt;(&quot;Error!,please try again&quot;,HttpStatus.INTERNAL_SERVER_ERROR);
          }
      }
  }
  </code></pre>