0

I am trying to fetch from the Yelp Fusion api with a small Spring Boot backend, however I am not actually gettting anything back in the response and can't find any information about the issue.

I have set up a fetch using a rest endpoint that I made to consume the yelp api and return the response to my frontend. I've tried messing with the searc parameters but not luck. I am expecting a simple response of 20 businesses within the set location.

YelpService:

package hangrydevelopment.hangrybackend.services;


//import hangrydevelopment.hangrybackend.models.Restaurant;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping(value = "/api/yelpFetch", produces = "application/json")
public class YelpService {

    @GetMapping("/{location}")
    public ResponseEntity<String> getRestaurants(@PathVariable String location) {
        HttpHeaders headers = new HttpHeaders();
        headers.add("Authorization", "Bearer YELP-API-KEY");
        headers.add("accept", "application/json");
        String url = "https://api.yelp.com/v3/businesses/search?location=" + location + "&term=fast%20food&radius=40000&categories=Fast%20food&open_now=true&sort_by=best_match&matches_party_size_param=true&limit=20";
        HttpEntity<Object> entity = new HttpEntity<Object>(headers);
        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);

        System.out.println(response);
        return response;
    }
}

Response:

<200,{"businesses": [], "total": 0, "region": {"center": {"longitude": -98.39630126953125, "latitude": 29.489805702433365}}},[Connection:"keep-alive", Content-Length:"119", content-type:"application/json", server:"envoy", x-zipkin-id:"500a9a12e3391cda", x-b3-sampled:"0", ratelimit-dailylimit:"5000", ratelimit-remaining:"4980", x-routing-service:"routing-main--useast1-64bdc8b4bb-kdhkg; site=public_api_v3", ratelimit-resettime:"2022-12-13T00:00:00+00:00", x-cloudmap:"routing_useast1", x-mode:"ro", x-proxied:"10-65-175-143-useast1bprod", x-extlb:"10-65-175-143-useast1bprod", cache-control:"max-age=0, no-store, private, no-transform", Accept-Ranges:"bytes", Date:"Mon, 12 Dec 2022 22:57:49 GMT", Via:"1.1 varnish", X-Served-By:"cache-iah17260-IAH", X-Cache:"MISS", X-Cache-Hits:"0"]>

Chase
  • 1

0 Answers0