Query Strings

The Query method is used to add a query string to the uri. Query takes one mandatory parameter an anonymous object representing the query string. The anonymous object also supports array values representing the query string.

Simple Object

dynamic client = new RestClient("http://jsonplaceholder.typicode.com");

//http://jsonplaceholder.typicode.com/users?id=2
await client.Users.Query(new { id = 2 }).Get(); 

Simple Array

dynamic client = new RestClient("http://jsonplaceholder.typicode.com");

//http://jsonplaceholder.typicode.com/users?id=1&id=2
await client.Users.Query(new { id = new[] { 1, 2 } }).Get(); 

Complex Array

dynamic client = new RestClient("http://jsonplaceholder.typicode.com");
var users =  new
             {
                user = new[] 
                { 
                   new { FirstName = "George", LastName = "Washington"  }, 
                   new { FirstName = "Abraham", LastName = "Lincoln" } 
                }
            }; 

//http://jsonplaceholder.typicode.com/users?user%5B0%5D.FirstName=George&user%5B0%5D.LastName=Washington&user%5B1%5D.FirstName=Abraham&user%5B1%5D.LastName=Lincoln
await client.Users.Query(users).Get(); 

Nested Object

dynamic client = new RestClient("http://jsonplaceholder.typicode.com");
var user = new 
           { 
             user = new { name="foo", email="foo@bar.com" }
           }; 

//http://jsonplaceholder.typicode.com/users?user.name=foo&user.email=foo@bar.com
await client.Users.Query(user).Get();