Skip to content
This repository has been archived by the owner on Aug 17, 2021. It is now read-only.
/ ScriptCs.Http Public archive

A cross platform ScriptCs library that allows you to make REST style Http requests

License

Notifications You must be signed in to change notification settings

VQComms/ScriptCs.Http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ScriptCs.Http NuGet

This is a cross platform ScriptCs library that allows you to make Http requests whilst also providing the ability to use strongly typed objects.

Usage

scriptcs -install ScriptCs.Http

public class Person
{
    public string FirstName{ get; set; }

    public string LastName{ get; set; }

    public string FullName{ get { return FirstName + " " + LastName; } }
}

var req = new Http();

req.Authenticator = new HttpBasicAuthenticator("username","password"); //takes any restsharp IAuthenticator
req.FollowRedirects = false;
req.DefaultHeaders = new Dictionary<string,string>{{"Accept", "application/json"}};
req.DefaultCookies = new List<Cookie>(new []{new Cookie()
                {
                    Domain = "localhost",
                    Value = "rocks",
                    Path = "/",
                    Name = "mycookie"
                }});

var resp = req.Get("http://localhost:5678/");
Console.WriteLine(resp.ContentType);

var resp2 = req.Get<List<Person>>("http://localhost:5678/",  new Dictionary<string, string>{ { "Accept", "application/xml" } }, new List<Cookie>(new []{new Cookie()
                {
                    Domain = "localhost",
                    Value = "rocksbetterthantheprevious",
                    Path = "/",
                    Name = "mycookie"
                }}));
Console.WriteLine(resp2.First().FullName);

var resp3 = req.Delete("http://localhost:5678/1");
Console.WriteLine(resp3.StatusCode);

var resp4 = req.Get<Person>("http://localhost:5678/3", new Dictionary<string, string>{ { "Accept", "application/xml" } });
Console.WriteLine(resp4.FullName);

var resp5 = req.Put("http://localhost:5678/1", new Person{ FirstName = "Changed", LastName = "Person" });
Console.WriteLine(resp5.StatusCode);

var resp6 = req.Post("http://localhost:5678/", new Person{ FirstName = "New", LastName = "Person" });
Console.WriteLine(resp6.StatusCode);

About

A cross platform ScriptCs library that allows you to make REST style Http requests

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages