Coder Social home page Coder Social logo

restivus's Introduction

Restivus Build status NuGet version

A simple, basic .NET REST library

Installation

Install-Package Restivus

Usage

Here's a quick and basic request to GitHub's API v3 using Restivus

// ...
using Newtonsoft.Json;
using Restivus;

class GitHubWebApi : IWebApi
{
    public string BasePath { get; } = "/";
    public string Host { get; } = "api.github.com";
    public int? Port { get; }
    public string Scheme { get; } = "https";
}

class GitHubRestClient : IRestClient
{
    public IReadOnlyCollection<IHttpRequestMiddleware> RequestMiddlewares { get; } =
        new List<IHttpRequestMiddleware>().AsReadOnly();

    public IHttpRequestSender RequestSender { get; } =
        new HttpRequestSender(YourApp.HttpClientInstance);

    public IWebApi WebApi { get; } = new GitHubWebApi();

    public Task<GitHubUser> GetUsers()
    {
        return this.Get().SendAsync(
            "/users",
            _DeserializeJson<IEnumerable<GitHubUser>>
        );
    }

    private async Task<T> _DeserializeJson<T>(HttpResponseMessage response)
    {
        response.EnsureSuccessStatusCode();

        return JsonConvert.DeserializeObject<T>(
            await response.Content.ReadAsStringAsync()
        );
    }
}

[JsonObject]
class GitHubUser { /* ... */ }

Publishing

Mostly a reminder for myself since I publish so infrequently:

git clean -xdf

# Build in Release config in VS

nuget pack -Properties Configuration=Release src/Restivus/Restivus.csproj

nuget push Restivus.<version>.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey $NUGET_API_KEY

restivus's People

Contributors

allanrsmith avatar awseward avatar mglodack avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

restivus's Issues

Cancellation Support

I would like to be able to pass a CancellationToken to all the exposed methods.

Better Response Handling

Hello,

This is a pretty sweet .NET rest client. Haven't found one this nice. ๐Ÿ‘

I would like to be able to add some hooks or be able to process the HttpResponseMessage myself.

Currently, if a bad request has happened it will throw an exception as demonstrated here. master...mglodack:fails_before_deserializing

I noticed that the SendAsync method is calling EnsureSuccessStatusCode() in the codebase here.

What do you thing about having the SendAsync method return HttpResponseMessage instead of type T?

Upload/Download file

I would like to be able to the do the following:

  1. Ability to upload using multipart/form-data with the option to report progress
  2. Ability to download a file and with the option to report progress

Downloading a file may not be as important because anyone can make use of the deserialize delegate to report progress.

There is a way to report progress by creating a custom HttpContent. Any interests in have that a part of this library or supporting file upload/downloads?

Handle query params in path gracefully

If I provide a path of /api/users?city=london, it should peel the query params off and include them properly instead of blowing up like it currently does.

Post provide a Generic Type instead of object

I did have a slight enhancement to the post method and possibly others that exposed a delegate to creating HttpContent.

I had to cast my object for this Func<object, HttpContent>. Any way we can make that a generic. Something like Func<T, HttpContent>?

Clarifying ISingleMethodRequestSender

I'm not sure I fully understand how to use ISingleMethodRequestSender.

Would you mind clarifying what this ISingleMethodRequestSender is for or how to use?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.