Skip to content

Instantly share code, notes, and snippets.

@dunglas
Created May 25, 2020 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dunglas/788b70312231d24e46d7632c634784f5 to your computer and use it in GitHub Desktop.
Save dunglas/788b70312231d24e46d7632c634784f5 to your computer and use it in GitHub Desktop.
URI Template test in Java
package com.example.demo;
import java.util.Map;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.UriTemplate;
@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/")
public String uriTemplate() {
UriTemplate ut = new UriTemplate("https://example.net/{ip}");
Map<String, String> m = ut.match("https://example.net/2001:db8::35");
return String.format("ip := %s", m.get("ip"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment