We will allow third-party clients to retrieve the search results via a REST API. These results will be available either in JSON or XML.
We want to handle requests of the /api/search/mixed;keywords=springFramework
form. This is really similar to the search form we already made, except that the request path begins with api
. Every URI found in this namespace should return binary results.
Let's create a new SearchApiController
class in the search.api
package:
package masterSpringMvc.search.api; import masterSpringMvc.search.SearchService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.social.twitter.api.Tweet; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController @RequestMapping("/api/search") public class SearchApiController { private SearchService searchService; @Autowired public SearchApiController(SearchService searchService) { this.searchService = searchService; } ...