TheOmenDen.Shared.JsonApi
1.7.25.101
Prefix Reserved
dotnet add package TheOmenDen.Shared.JsonApi --version 1.7.25.101
NuGet\Install-Package TheOmenDen.Shared.JsonApi -Version 1.7.25.101
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="TheOmenDen.Shared.JsonApi" Version="1.7.25.101" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TheOmenDen.Shared.JsonApi --version 1.7.25.101
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TheOmenDen.Shared.JsonApi, 1.7.25.101"
#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.
// Install TheOmenDen.Shared.JsonApi as a Cake Addin #addin nuget:?package=TheOmenDen.Shared.JsonApi&version=1.7.25.101 // Install TheOmenDen.Shared.JsonApi as a Cake Tool #tool nuget:?package=TheOmenDen.Shared.JsonApi&version=1.7.25.101
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
This library aims to accomplish the following goals
- Provide a stable implementation of the JSON:API standard
- Allow for the ability to stream results via
IAsyncEnumerable
implementations - Allow for the ability for
Links
to maintain immutability - Allow for the ability for
Errors
to maintain immutability - Allow for the ability to generate relationships and attributes
- Allow for the ability to stream results via
- Provide a template for validations of basic view models and other resource objects
- Provide strict typing for View Models
- Provide for strict typing on relationships, while maintaining easy JSON Serialization
- Provide a simple, easy to understand JSON document to be interpreted by any API consumer
- By conforming to the JSON API standard, any
Hypermedia
based API Consumer should be able to read and consume the JSON Document - By allowing for the links object to contain references to specific endpoints, the API Consumer should be able to utilize specific endpoints
- By allowing for "Included" properties, the API Consumer should be able to create less HTTP requests overall
- By conforming to the JSON API standard, any
- Provide simple extension methods for easy access to the
IViewModel
interface
This library is sourced/inspired by:
An example of using the Fluent API to build a view model
Then you can use a source generator to generate the json from this later!
var vm = ViewModelBuilder<TestClass>
.CreateBuilder()
.FromData(testClass)
.WithLinks()
.AddSelfLink()
.AddLink(PaginationLink.First("/test?page=1"))
.WithRelatedData()
.AddRelationship(test2.Name, test2)
.WithSelfLink<TestClass>(test2.Name)
.Include(ViewModelBuilder<TestClass>
.CreateBuilder()
.FromData(test2)
.Build)
.WithRelatedData()
.AddRelationship(test3.Id.ToString(), test3)
.WithSelfLink<Additional>(test3.Id.ToString())
.DoNotInclude()
.Build();
Console.WriterLine(JsonSerializer.Serialize(vm, ViewModelContext.Default.IViewModel));
An example of Declaring a Collection of ViewModels - with relationships
Using the above Fluent API to build a view model, then creating a view model collection from other data
var testClass = new TestClass
{
Count = 1,
Description = "Short dumb description",
Name = "Test 1"
};
var test2 = new TestClass
{
Count = 2,
Description = "Relate Me",
Name = "Test 2"
};
var test3 = new Additional
{
Id = Guid.NewGuid(),
Count = 1,
Name = "Additional Class To Relate"
};
var vm = ViewModelBuilder<TestClass>
.CreateBuilder()
.FromData(testClass)
.WithLinks()
.AddSelfLink()
.AddLink(PaginationLink.First("/test?page=1"))
.WithRelatedData()
.AddRelationship(test2.Name, test2)
.WithSelfLink<TestClass>(test2.Name)
.Include(ViewModelBuilder<TestClass>
.CreateBuilder()
.FromData(test2)
.Build)
.WithRelatedData()
.AddRelationship(test3.Id.ToString(), test3)
.WithSelfLink<Additional>(test3.Id.ToString())
.DoNotInclude()
.Build();
var createListOfVm = new List<ViewModel<TestClass>> { vm };
var vmc = ViewModelCollection<TestClass>.From(createListOfVm);
This library also includes the ability to work with simple source generated System.Text.Json
Contexts based off of the IViewModel
type
Example: Using the built-in Serialization context for a minimal API
app.MapGet("/getVm", () => JsonSerializer.Serialize(vmc, ViewModelContext.Default.IViewModel));
ToDos
- Finish Async Streaming Implementations
- The way they are currently implemented limits the functionality of the
AsyncStreamingViewModelCollection
to only provide controller support. - We want to change this to provide support for streaming through Minimal APIs
- The way they are currently implemented limits the functionality of the
- Work on providing more Generic typing support for JSON Serialization
- This is a
.NET
and aSystem.Text.Json
limitation. - Current proposed fix is in
.NET 7
- This is a
- Add support for customizable collection returns
- Currently due to the way we've worked with reflection, the collection models/view models return relatively hard to understand results
- Improve fluent interface
- Allow for the ability to customize relationships further
- Allow for the ability to customize
selfUrl
further when callingAddSelfLink/WithSelfLink
- Allow for the ability to add relationships for the collection types
- Continue to provide maintainence and optimizations
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.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 |
---|---|---|
1.7.25.101 | 242 | 7/25/2022 |