Skip to content
Snippets Groups Projects
Commit fb19d8c3 authored by 김준하's avatar 김준하
Browse files

musicSearch request code

parent 56a26872
No related branches found
No related tags found
1 merge request!2Master
...@@ -4,6 +4,7 @@ import com.ajou.prcoding.myweb.dto.MusicList; ...@@ -4,6 +4,7 @@ import com.ajou.prcoding.myweb.dto.MusicList;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
...@@ -29,6 +30,19 @@ public class MyWebController { ...@@ -29,6 +30,19 @@ public class MyWebController {
} }
} }
@GetMapping(value="/musicSearch")
public MusicList musicSearchByParam(@RequestParam String term){
try {
String url = "https://itunes.apple.com/search?term=" + term + "&entity=album";
String response = restTemplate.getForObject(url, String.class);
ObjectMapper mapper = new ObjectMapper();
MusicList list = mapper.readValue(response, MusicList.class);
System.out.println(list.getResultCount());
return list;
} catch(IOException e) {
System.out.println(e.toString());
return null;
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment