Нет описания

Robert Marshall b56b633232 Update all the things 1 год назад
.nuke b56b633232 Update all the things 1 год назад
build b56b633232 Update all the things 1 год назад
src b56b633232 Update all the things 1 год назад
.drone.yml b56b633232 Update all the things 1 год назад
.editorconfig 35fc3df32e Move ApiClient out of Website repo 4 лет назад
.gitignore b56b633232 Update all the things 1 год назад
Readme.md b1f604ea75 Add readme 4 лет назад
build.cmd b56b633232 Update all the things 1 год назад
build.ps1 b56b633232 Update all the things 1 год назад
build.sh b56b633232 Update all the things 1 год назад

Readme.md

Build Status

API Client library

Simple project to server 2 purposes

Usage

ApiClient

ApiClient is an abstract class designed to be inherited from for your actual API calls. It requires an instance of CacheDurations to be passed in to the constructor.

To use, simply inherit from ApiClient and use Post for posting data and Get for getting data. Both Post and Get are generic methods and will deserialise and return the type you specify. They both take anonymous objects for their query parameters.

Signatures:

protected async Task<T> Post<T>(string url, object value, object query = null);
protected async Task<T> Get<T>(string url, object query = null);

Example:

public async Task<IEnumerable<BlogPost>> GetLatestPostsAsync(int count = 0, int offset = 0) => await Get<IEnumerable<BlogPost>>("getlatestposts", new{count, offset});
public async Task<BlogPost> SavePostAsync(BlogPostSubmission post) => await Post<BlogPost>("savepost", post);

CacheDurations

Create an instance of CacheDurations with your various as you would with a dictionary initialiser:

new CacheDurations
{
	{
		"class", new Dictionary<string, int>
		{
			{"method", 1}
		}
	}
};

For MVC

In your Startup.cs add this to your ConfigureServices method:

services.AddSingleton(Configuration.GetSection("cacheDurations").Get<CacheDurations>());

Settings take the following format in appsettings.json:

"cacheDurations": {
	"default": {
			"default": 30 // default cache time for all calls
	},
	"BlogApi": { // override default cache time for class
		"default": 60, // default for this class
		"GetPostByUrlAsync": 120, // override for this method
	}
}