StrapiSharp 0.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package StrapiSharp --version 0.1.2
                    
NuGet\Install-Package StrapiSharp -Version 0.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StrapiSharp" Version="0.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StrapiSharp" Version="0.1.2" />
                    
Directory.Packages.props
<PackageReference Include="StrapiSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add StrapiSharp --version 0.1.2
                    
#r "nuget: StrapiSharp, 0.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package StrapiSharp@0.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=StrapiSharp&version=0.1.2
                    
Install as a Cake Addin
#tool nuget:?package=StrapiSharp&version=0.1.2
                    
Install as a Cake Tool

Build Status

StrapiSharp

This project builds a binding around the Strapi API to ease the communication between a .NET project and a Strapi backend; attempting to eliminate the need to write any HttpClient code yourself. A decision has been made at this time to only provide string results from requests; this allows you to bring your own JSON Serializer logic.

Tech Stack

C# 7.0, NUnit, Fluent Assertions

Documentation

At this time there is no formal documentation. I have tried to provide fairly detailed documentation comments throughout, but have not generated anything further at this point.

Usage/Examples

Add the StrapiSharp package to your project by means of dotnet add package StrapiSharp, this will pull from NuGet.

Basic example of querying a posts resource from Strapi.

using StrapiSharp;
using StrapiSharp.Requests;

var strapi = new Strapi("http://localhost:1337/api");
var request = new QueryRequest("posts");
var result = await strapi.ExecuteAsync(request);
Console.WriteLine(result);

Example of querying and filtering a posts example resource from Strapi.

using StrapiSharp;
using StrapiSharp.Enums;
using StrapiSharp.Requests;

var strapi = new Strapi("http://localhost:1337/api");
var request = new QueryRequest("posts");
request.Filter(FilterType.EqualTo, "id", "42");

var result = await strapi.ExecuteAsync(request);
Console.WriteLine(result);

Example of querying, filtering, and sorting a posts example resource from Strapi.

using StrapiSharp;
using StrapiSharp.Enums;
using StrapiSharp.Requests;

var strapi = new Strapi("http://localhost:1337/api");
var request = new QueryRequest("posts");
request.Filter(FilterType.GreaterThan, "id", "2");
request.Sort("slug", SortDirection.Descending);
request.LimitTo(3);

var result = await strapi.ExecuteAsync(request);
Console.WriteLine(result);

Example of catching a StrapiRequestException and extracting data from within.

using System.Text.Json;
using System.Text.Json.Serialization;
using StrapiSharp;
using StrapiSharp.Requests;
using StrapiSharp.Requests.Convenience;

try
{
	var login = new LoginRequest("username", "password");
	await strapi.ExecuteAsync(login);
}
catch(StrapiRequestException ex)
{
	Console.WriteLine(ex.Message);
	var error = JsonSerializer.Deserialize<ResponseModels.Response>(ex.Response)!.Error;
	Console.WriteLine($"{error!.Name} with status {error.Status}. {error!.Message}");
	Console.ReadLine();
}

namespace ResponseModels
{
	public partial class Response
	{
		[JsonPropertyName("data")]
		public object? Data { get; set; }

		[JsonPropertyName("error")]
		public Error? Error { get; set; }
	}

	public partial class Error
	{
		[JsonPropertyName("status")]
		public long Status { get; set; }

		[JsonPropertyName("name")]
		public string? Name { get; set; }

		[JsonPropertyName("message")]
		public string? Message { get; set; }
	}
}

Running Tests

To run the test suite, run the following command

  dotnet test

Acknowledgements

License

MIT

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.4 3,801 7/12/2023
0.1.3 365 4/27/2023
0.1.2 247 4/11/2023
0.1.1 350 4/11/2023
0.1.0 277 3/27/2023