Designed to help C# programmers creating HTTP Requests, this is The Hypertext Transfer Unicorn 🦄
You can get HttpUnicorn by installing our NuGet Package;
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:
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
}
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
}
Todo updatedTodo = await new Unicorn(config)
.PutModelAsync<Todo, Todo>(todo);
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.
Tyler Mendes de Brito - @tylerbryto (Github) – colorigotica (Twitter) – tyler.brito99@gmail.com
See git flow cheatsheet.
- Fork it (https://github.com/tylerbryto/httunicorn/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request
- Wait for our response