Skip to content

Designed to help C# programmers creating HTTP Requests, this is The Hypertext Transfer Unicorn 🦄

License

Notifications You must be signed in to change notification settings

uneecorn/httunicorn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HttUnicorn v0.1.0

NuGet

Designed to help C# programmers creating HTTP Requests, this is The Hypertext Transfer Unicorn 🦄

Usage

Nuget

You can get HttpUnicorn by installing our NuGet Package;

Config

HttUnicorn uses a config object called UnicornConfig that need a string with the url.

var config = new UnicornConfig("http://localhost:3000/todos/");

You can also use UnicornConfig to set the Timeout and Headers

var config = new UnicornConfig(
  "http://localhost:3000/todos/",
  timeout: new TimeSpan(0, 0, 45),
  headers: new List<UnicornHeader>
  {
    new UnicornHeader("header_name", "header_value"),
    new UnicornHeader("other_header_name", "other_header_value")
  });

You can pass the timeout directly as seconds

var config = new UnicornConfig(
  "http://localhost:3000/todos/",
  timeoutSeconds: 35
  );

You can start following the examples bellow:

Get

List<Todo> todos = await new Unicorn(config).GetModelAsync<List<Todo>>();

string todosString = await new Unicorn(config).GetStringAsync();

using(HttpResponseMessage responseMessage = 
  await new Unicorn(config).GetResponsegAsync())
{
    //deal with the response message
}

Post

Todo generatedTodo = await new Unicorn(config)
  .PostModelAsync<Todo, Todo>(new Todo
  {
    Completed = true,
    Title = "todo",
    UserId = 36
  });
string stringResponseBody = await new Unicorn(config)
  .PostStringAsync(new Todo
  {
    Completed = true,
    Title = "todo",
    UserId = 36
  });
using(HttpResponseMessage responseMessage = 
  await new Unicorn(config).PostResponsegAsync())
{
    //deal with the response message
}

Put

Todo updatedTodo = await new Unicorn(config)
                    .PutModelAsync<Todo, Todo>(todo);

Delete

MyApiResponse response = await new new Unicorn(config)
                          .DeleteModelAsync<MyApiResponse>(key);
//This one is for situations when the requested API returns an object in the body of the response.

Contact us

Tyler Mendes de Brito - @tylerbryto (Github)colorigotica (Twitter)tyler.brito99@gmail.com

Contributing

See git flow cheatsheet.

  1. Fork it (https://github.com/tylerbryto/httunicorn/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request
  6. Wait for our response


About

Designed to help C# programmers creating HTTP Requests, this is The Hypertext Transfer Unicorn 🦄

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages