Browse Source

fix: update C# example

Sv443 1 month ago
parent
commit
a713aa5d96
1 changed files with 17 additions and 8 deletions
  1. 17 8
      docs/raw/index.html

+ 17 - 8
docs/raw/index.html

@@ -1379,7 +1379,7 @@ namespace JokeAPIExample
 <div class="actualCode">using System;
 using System.Threading.Tasks;
 using System.Net.Http;
-using Newtonsoft.Json;   // Install with NuGet Package Manager: https://www.nuget.org/packages/Newtonsoft.Json/12.0.3?_src=template
+using Newtonsoft.Json; // install with NuGet
 
 namespace TestHttpRequest
 {
@@ -1387,7 +1387,9 @@ namespace TestHttpRequest
     {
         static async Task Main(string[] args)
         {
-            Joke randomJoke = await GetJokeAdvanced();
+            Console.Write("\n");
+
+            Joke randomJoke = await GetJoke();
             if (randomJoke.type == "single")
             {
                 Console.WriteLine(randomJoke.joke);
@@ -1395,18 +1397,23 @@ namespace TestHttpRequest
             else
             {
                 Console.WriteLine(randomJoke.setup);
+                Console.WriteLine("...");
                 System.Threading.Thread.Sleep(3000);
                 Console.WriteLine(randomJoke.delivery);
             }
+
+            Console.Write("\n");
         }
 
-        public async static Task<Joke> GetJokeAdvanced()
+        public async static Task<Joke> GetJoke()
         {
-            const string baseUrl = "https://jokeapi.dev";
-            string[] categories = { "Programming", "Miscellaneous", "Pun", "Spooky", "Christmas" };
+            const string baseUrl = "https://v2.jokeapi.dev";
+            string[] categories = { "Programming", "Miscellaneous", "Pun" };
             string[] parameters = {
                 "blacklistFlags=nsfw,religious,racist,sexist",
-                "idRange=0-100"
+                "idRange=0-100",
+                "safe-mode",
+                "lang=en"
             };
             string requestUrl = $"{baseUrl}/joke/{string.Join(",", categories)}?{string.Join("&", parameters)}";
             Joke randomJoke;
@@ -1427,11 +1434,12 @@ namespace TestHttpRequest
         public string joke { get; set; }
         public string setup { get; set; }
         public string delivery { get; set; }
-        public int id { get; set; }
         public Flags flags { get; set; }
+        public int id { get; set; }
+        public bool safe { get; set; }
+        public string lang { get; set; }
     }
 
-
     public class Flags
     {
         public bool nsfw { get; set; }
@@ -1439,6 +1447,7 @@ namespace TestHttpRequest
         public bool political { get; set; }
         public bool racist { get; set; }
         public bool sexist { get; set; }
+        public bool @explicit { get; set; } // use @ since "explicit" is a reserved keyword
     }
 }</div></code>
                 </details><br>