Skip to content

Repository files navigation

RestClient.NET

A .NET Library aimed to simplify the writing of REST API Clients

Example

publicclassOpenWeatherMapAPI:RestClientBase{publicOpenWeatherMapAPI():base(DataTypes.JSON){}protectedoverridestringUrl{get{return"http://api.openweathermap.org/data/2.5/";}}protectedoverrideHttpClientSetupConnection(){returnnewHttpClient();}publicWeatherResultGetWeather(stringquery){returnSendRequest<WeatherResult,WeatherGetRequest,WeatherErrorResult>(newWeatherGetRequest(){Query=query});}publicTask<WeatherResult>GetWeatherAsync(stringquery){returnSendRequestAsync<WeatherResult,WeatherGetRequest,WeatherErrorResult>(newWeatherGetRequest(){Query=query});}[DataContract][SegmentDef(1,UrlDefinitionDataTypes.Static,"weather")][ParameterDef("q",UrlDefinitionDataTypes.Data,"Query")]protectedclassWeatherGetRequest:RestGetRequest{publicstringQuery{get;set;}}[DataContract]publicclassWeatherResult:RestResult{[DataMember(Name="name")]publicstringName{get;set;}[DataMember(Name="dt")]publicintTimeStamp{get;set;}[DataMember(Name="id")]publicintID{get;set;}[DataMember(Name="cod")]publicintCod{get;set;}}[DataContract]protectedclassWeatherErrorResult:RestErrorResult{}}using(OpenWeatherMapAPIapi=newOpenWeatherMapAPI()){//Make a Sync call.OpenWeatherMapAPI.WeatherResultresult=api.GetWeather("London,Ca");//Use result dataConsole.WriteLine(result.Name+" "+result.TimeStamp);//Make an Async call.Task<OpenWeatherMapAPI.WeatherResult>task=api.GetWeatherAsync("Fenton,Mi");//do other stuffConsole.WriteLine("OtherStuff");//Use result datatask.Wait();Console.WriteLine(task.Result.Name+" "+task.Result.TimeStamp);}

Release Build Status

Build status

Release Builds are available here: https://ci.appveyor.com/project/nathanmentley/restclient-net-837

Development Build Status

Build status

Bleeding Edge builds are available here: https://ci.appveyor.com/project/nathanmentley/restclient-net

License

RestClient.NET is released under the MIT License: https://tldrlegal.com/license/mit-license

About

A .NET Library aimed to simplify the writing of REST API Clients

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages