No description
Find a file
2023-02-18 13:23:54 +00:00
.nuke Update all the things 2023-02-18 13:23:54 +00:00
build Update all the things 2023-02-18 13:23:54 +00:00
src Update all the things 2023-02-18 13:23:54 +00:00
.drone.yml Update all the things 2023-02-18 13:23:54 +00:00
.editorconfig Move ApiClient out of Website repo 2020-06-23 11:46:19 +01:00
.gitignore Update all the things 2023-02-18 13:23:54 +00:00
build.cmd Update all the things 2023-02-18 13:23:54 +00:00
build.ps1 Update all the things 2023-02-18 13:23:54 +00:00
build.sh Update all the things 2023-02-18 13:23:54 +00:00
Readme.md Add readme 2020-06-23 13:01:24 +01:00

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
	}
}