Search code examples
c#umbraco7yelp

How to use Yelp API v2 C# example in Umbraco site


I'm new to .net and Umbraco in general. I have a basic site setup and want to use the Yelp API to display some content on the site. I've played with the code sample from git:

https://github.com/Yelp/yelp-api/tree/master/v2/csharp

And have successfully built that, which produces an executable command line program. My question is, how do I convert the code from the sample for use directly on the website, specifically Umbraco v7?

Any help much appreciated, thanks.


Solution

  • Your code should not differ a lot from the example combined with normal ASP.NET.

    If you are in a Partial view or Template in Umbraco your Razor code could look something like:

    @{
      // todo: add other relevant code or link to other classes encapsulating your calls
      JObject response = client.Search(term, location);
      JArray businesses = (JArray)response.GetValue("businesses");
    }
    
    <ul>
      @foreach(var item in businesses) {
        <li>id: @item["id"]</li>
      }
    </ul>