예제 #1
0
        public void Execute_OneParameter_CorrectResponse()
        {
            var baseUrl   = new LiteralScalarResolver <string>("https://api.agify.io/");
            var parameter = new ParameterRest(
                new LiteralScalarResolver <string>("name"),
                new LiteralScalarResolver <string>("cedric")
                );
            var engine = new RestEngine(new Anonymous(), baseUrl, null, new[] { parameter }, null, null);
            var result = engine.Execute();

            Assert.That(result, Does.StartWith("{\"name\":\"cedric\",\"age\":"));
        }
예제 #2
0
        public void Execute_Segments_CorrectResponse()
        {
            var baseUrl = new LiteralScalarResolver <string>("https://verse.pawelad.xyz/");
            var path    = new LiteralScalarResolver <string>("/projects/{project}/");
            var segment = new SegmentRest(
                new LiteralScalarResolver <string>("project"),
                new LiteralScalarResolver <string>("jekyll")
                );
            var parameter = new ParameterRest(
                new LiteralScalarResolver <string>("format"),
                new LiteralScalarResolver <string>("json")
                );
            var engine = new RestEngine(new Anonymous(), baseUrl, path, new[] { parameter }, new[] { segment }, null);
            var result = engine.Execute();

            Assert.That(result, Does.StartWith("{\"latest\":"));
        }
예제 #3
0
        public void Execute_PathAndParameters_CorrectResponse()
        {
            var baseUrl    = new LiteralScalarResolver <string>("https://api.publicapis.org/");
            var path       = new LiteralScalarResolver <string>("entries");
            var parameter1 = new ParameterRest(
                new LiteralScalarResolver <string>("category"),
                new LiteralScalarResolver <string>("animals")
                );
            var parameter2 = new ParameterRest(
                new LiteralScalarResolver <string>("https"),
                new LiteralScalarResolver <string>("true")
                );
            var engine = new RestEngine(new Anonymous(), baseUrl, path, new[] { parameter1, parameter2 }, null, null);
            var result = engine.Execute();

            Assert.That(result.Length, Is.GreaterThan(20));
            Assert.That(result, Does.StartWith("{\"count\":"));
        }
예제 #4
0
        static void Main(string[] args)
        {
            //We create a new instance of RestEngine
            var engine = new RestEngine("https://reqres.in/api/", "application/json")
                         .AddHeader("User-Agent", "RestEngine .NET");
            var task   = engine.ProcessGetSync("users");
            var result = task.Content.ReadAsStringAsync().Result;

            Console.WriteLine(result);


            engine.ClearUriParams()
            .ClearHeaders()
            .AddAccept("application/json")
            .AddHeader("User-Agent", ".NET Foundation Repository Reporter")
            .AddUriParam("users")
            .AddQueryParam("page", "3");
            var task2   = engine.ProcessGetSync();
            var result2 = task.Content.ReadAsStringAsync().Result;

            Console.WriteLine(result2);

            engine.AddUriParam("1");
            var task3   = engine.ProcessGetSync();
            var result3 = task.Content.ReadAsStringAsync().Result;

            Console.WriteLine(result3);

            engine.AddUriParam("2");
            task3   = engine.ProcessGetSync();
            result3 = task.Content.ReadAsStringAsync().Result;
            Console.WriteLine(result3);

            engine.ClearUriParams().AddUriParam("users").AddQueryParam("page", "2");
            task3   = engine.ProcessGetSync();
            result3 = task.Content.ReadAsStringAsync().Result;
            Console.WriteLine(result3);

            Console.WriteLine("Press Any Key To Finish");
            Console.ReadLine();
        }
예제 #5
0
파일: RestReaderArgs.cs 프로젝트: ywscr/NBi
 public RestReaderArgs(RestEngine rest)
 => (Rest) = (rest);