Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/igorkulman/kulman.wpa81.baserestservice
Base class for a Windows Phone 8.1 XAML, Windows 8.1 and Windows 10 Universal REST service implementation
https://github.com/igorkulman/kulman.wpa81.baserestservice
api c-sharp json rest uwp
Last synced: 6 days ago
JSON representation
Base class for a Windows Phone 8.1 XAML, Windows 8.1 and Windows 10 Universal REST service implementation
- Host: GitHub
- URL: https://github.com/igorkulman/kulman.wpa81.baserestservice
- Owner: igorkulman
- License: mit
- Created: 2014-11-23T12:41:11.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-29T08:12:04.000Z (about 8 years ago)
- Last Synced: 2024-10-04T13:06:42.713Z (about 1 month ago)
- Topics: api, c-sharp, json, rest, uwp
- Language: C#
- Homepage:
- Size: 160 KB
- Stars: 18
- Watchers: 5
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Base REST service for Universal Apps
============================[![NuGet version](http://img.shields.io/nuget/v/Kulman.WPA81.BaseRestService.svg?style=flat)](https://nuget.org/packages/Kulman.WPA81.BaseRestService) [![Build status](https://ci.appveyor.com/api/projects/status/tyk3ff6jamxondgh?svg=true)](https://ci.appveyor.com/project/igorkulman/kulman-wpa81-baserestservice) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/igorkulman/Kulman.WPA81.BaseRestService/master/LICENSE) ![UWP ready](https://img.shields.io/badge/platform-uwp-green.svg) ![WinRT ready](https://img.shields.io/badge/platform-winrt-green.svg) ![WPA81 ready](https://img.shields.io/badge/platform-wpa81-green.svg)
Base class for a Windows Phone 8.1 (Silverlight), Windows Phone 8.1 XAML and Windows 8.1 REST service implementation. Also works fin in Windows 10 projects (UWP).
## Installation
PM> Install-Package Kulman.WPA81.BaseRestService
## UsageCreate your service class and inherit from BaseRestService. The minimum you need to do to make it work is to override the GetBaseUrl() method to set the base url for all the requests.
```csharp
public class MyDataService: BaseRestService
{
protected override string GetBaseUrl()
{
return "my base url";
}
}
```
You can (but do not have to) also override the GetRequestHeaders() method to set the default request headers.
```csharp
protected override Dictionary GetRequestHeaders(string requestUrl)
{
return new Dictionary
{
{ "Accept-Encoding", "gzip, deflate" },
{ "Accept", "application/json" },
};
}
```You can also override the `CreateJsonSerializerSettings` method with you need custom JSON deserialization settings.
Now you can use the following methods in your class:
```csharp
Task Get(string url);
Task Put(string url, object request);
Task Post(string url, object request);
Task Patch(string url, object request);
Task Delete(string url);
Task> Head(string url);
```If you need to get the raw request, there are overloads returning `HttpResponseMessage`:
```csharp
Task Get(string url);
Task Put(string url, object request);
Task Post(string url, object request);
Task Patch(string url, object request);
```All the available methods have overloads accepting and `CancellationToken`.
Methods in your service may then look like this
```csharp
public Task> GetAccounts()
{
return Get>("/accounts");
}
public Task UpdateAccount(Account account)
{
return Patch("/accounts",account);
}
```For more information, see my blog post [REST service base class for Windows Phone 8.1 XAML apps](http://blog.kulman.sk/rest-service-base-class-for-windows-phone-8-1-xaml-apps/).
For changes, [see the changelog](https://github.com/igorkulman/Kulman.WPA81.BaseRestService/blob/master/CHANGELOG.md).