An unofficial .NET Core client for the Write.as API written in C#.
Update Version 1.2.0:
The latest version of the source code now allows you to enter an API key when initializing a
WriteAsClient instance. This API key will allow you to bypass the rate limiting checks on the Write.as API.
Some basic in-memory caching has also been added to the client. You can configure some of the cache settings when initializing a
WriteAsClient instance. The new settings are described below:
cacheExpirationInSecondsdetermines how long data will stay in the cache before it expires. The default value for this setting is 300 seconds.
cacheSizedetermines how many objects it can store in the cache. Note that a collection of posts (
List<Post>) and a single post each count as 1 item. The default value for this setting is 4.
This wrapper library is being used to power a number of other Blazor WASM apps I've written:
Update on those apps listed above:
- It used to work for the apps listed above, but because those are Blazor WebAssemnbly apps, they are now being hindered by CORS errors outside of my control. This client/wrapper library itself still works, like from a console application. It just doesn't work on a purely client side web application without going through a CORS proxy.
Currently Supported Operations
Task<List<Post>> GetAllPosts(string alias, SortOrder sortOrder = SortOrder.Descending); Task<Post> GetPostById(string postId); Task<Post> GetPostBySlug(string alias, string slug); Task<List<Post>> GetPostsByPageNumber(string alias, int pageNumber, SortOrder sortOrder = SortOrder.Descending); Task<List<Post>> Search(string alias, string searchKey, SortOrder sortOrder = SortOrder.Descending);
Initialize new instance -- Note: To avoid creating multiple socket connections, initialize a single
WriteAsClient instance and use it throughout the whole app.
var client = new WriteAsClient("https://write.as/", apiKey, cacheExpirationInSeconds, cacheSize);
List<Post> allPosts = await client.GetAllPosts(alias, sortOrder);
List<Post> allPosts = await client.GetPostsByPageNumber(alias, pageNumber, sortOrder);
Post post = await client.GetPostBySlug(alias, slug);
Post post = await client.GetPostById(postId);
List<Post> searchResults = await client.Search(alias, searchKey);
You can install via nuget:
Install-Package WriteAs.NET -Version 1.2.0
Or via the .NET Core command line interface:
dotnet add package WriteAs.NET --version 1.2.0