Example #1
0
        public static RestClient get(int id, Func <Product, int> toDo)
        {
            RestClient client = new RestClient();

            client.BaseUrl = new Uri("https://reqres.in/");

            var request = new RestRequest();

            request.Resource = String.Format("api/users/{0}", id);

            IRestResponse     response   = client.Execute(request);
            ProductObjectRest rootObject = null;

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                RestSharp.Deserializers.JsonDeserializer deserial = new RestSharp.Deserializers.JsonDeserializer();
                rootObject = deserial.Deserialize <ProductObjectRest>(response);
                //return rootObject.data;
            }
            else
            {
                rootObject = new ProductObjectRest();
                //return rootObject.data;
            }

            toDo(rootObject.data);
            return(client);
        }
Example #2
0
        public static RestClient sync(Func <List <Product>, int> toDo)
        {
            var client = new RestClient();

            client.BaseUrl = new Uri("https://reqres.in/");

            var request = new RestRequest();

            request.Resource = "api/users";

            IRestResponse response = client.Execute(request);
            ProductRest   rootObject;

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                RestSharp.Deserializers.JsonDeserializer deserial = new RestSharp.Deserializers.JsonDeserializer();
                rootObject = deserial.Deserialize <ProductRest>(response);
                //return rootObject.data;
            }
            else
            {
                rootObject = new ProductRest();
                //return rootObject.data;
            }
            toDo(rootObject.data);
            return(client);
        }
Example #3
0
        public static List <Products> sync()
        {
            var client = new RestClient();

            client.BaseUrl = new Uri("http://eslansasac.syslacstraining.com/");

            var request = new RestRequest();

            request.Resource = "api/productos";

            IRestResponse response = client.Execute(request);
            ProductRest   rootObject;

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                RestSharp.Deserializers.JsonDeserializer deserial = new RestSharp.Deserializers.JsonDeserializer();
                rootObject = deserial.Deserialize <ProductRest>(response);
                //return rootObject.data;
            }
            else
            {
                rootObject = new ProductRest();
                //return rootObject.data;
            }
            return(rootObject.data);
        }
        public static List <Comment> CommentDeserialize(IRestResponse response)
        {
            RestSharp.Deserializers.JsonDeserializer deserial = new RestSharp.Deserializers.JsonDeserializer();
            var commentObject = deserial.Deserialize <List <Comment> >(response);

            return(commentObject);
        }
        public static string ReturnJsonValue(string valueKey, IRestResponse response)
        {
            RestSharp.Deserializers.JsonDeserializer jsonDeserialize = new RestSharp.Deserializers.JsonDeserializer();
            var jsonDeserializedObject = jsonDeserialize.Deserialize <Dictionary <string, string> >(response);

            return(jsonDeserializedObject[valueKey]);
        }
Example #6
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        // Usar la libreria RestSharp
        RestClient client   = new RestClient("http://localhost:8080/");
        var        request  = new RestRequest("Country", Method.GET);
        var        response = client.Execute(request);

        RestSharp.Deserializers.JsonDeserializer jsonds = new RestSharp.Deserializers.JsonDeserializer();
        var LResult = jsonds.Deserialize <List <CountryEntity> >(response);

        GridView1.DataSource = LResult;
        GridView1.DataBind();
    }