HTTP GET Method – Ways to form GET URL

In this article let us see the ways to form GET URL for http requests. We are going to use Spring Boot and Google Chrome Postman to verify the URL formation.

Common ways of forming GET url’s are by

  1. Path
  2. Body

Query: (Path)

When GET URL is formed along with query, the URL will look like,


Params: (Body)

When GET URL is formed along with Params, we will send the parameters along with the body.


There are four parameters with request param,

  • defaultValue – This is the default value, if the request is not having the value or it is empty.
  • name – Parameter name
  • required – true, if we want to make the parameter required one.
  • value – value of the parameter

Now let us see an example – Various ways to form GET URL.
I have created a simple springboot application with a controller. The output shown below are from chrome postman application.

you can download the code here

package com.javainfinite;


import org.apache.http.client.utils.URIBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.UriComponentsBuilder;

public class UrlController {
	public String homepage() {
		return "success";
	public String pathVariableId(@PathVariable("id") Integer id) {
		return "Welcome to Java Infinite - id: "+id;
	public String idParam(@RequestParam("id") Integer id) {
		return "Welcome to Java Infinite - Param ID: "+id;
	public String multipleParams(@RequestParam("name") String name, @RequestParam("age") String age ) {
		return "Welcome to Java Infinite - Multiple Params - Name: "+name+" age: "+age;
	public String uriComponentBuild() {
		UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("");
		builder.queryParam("id", "1");
		builder.queryParam("One", "2");
		String url = builder.toUriString();
		return url;
	public String formation() {
		String uriBuild = null;
		try {
			URIBuilder b = new URIBuilder("");
			b.addParameter("one", "1");
			b.addParameter("two", "two");
			URL url =;
			uriBuild = url.toString();
		} catch (URISyntaxException e) {
		} catch (MalformedURLException e) {
		return uriBuild;

package com.javainfinite;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

 * java infinite!
public class App 
    public static void main( String[] args )
    {, args);









Download here


By Sri

Leave a Reply

Your email address will not be published. Required fields are marked *