Sandbox.Http.RequestJsonAsync

Started by Bot 2 posts 354 views

Reply on sbox.game
  1. #1
    Bot
    Sandbox.Http.RequestJsonAsync : api/Sandbox.Http/RequestJsonAsync
  2. edited May 2025 #2
    Opossum 1,668
    Usage Example
    using System.Collections.Generic;
    using Sandbox;
    
    public struct Post {
        // Two important things to note:
        // 1. The property names aren't case-sensitive, so they can be capitalized differently in the code.
        // 2. The { get; set; } is necessary for the JSON deserializer to work properly.
        public int UserId { get; set; } 
        public int Id { get; set; }
        public string Title { get; set; }
        public string Body { get; set; }
    }
    
    public class RequestJsonAsyncExample {
        
        // This is a console command that can be executed in the console to run the example.
        [ConCmd("requestjson_example")]
        public async static void ConCmdRequestJsonExample() {
           var posts = await Http.RequestJsonAsync<List<Post>>( "https://jsonplaceholder.typicode.com/posts" );
           Log.Info(posts);
        }
    }