research-institute - JsonApiDotNetCore 2.0.0-alpha1-0109

Package Description

PM> Install-Package JsonApiDotNetCore -Version 2.0.0-alpha1-0109 -Source https://www.myget.org/F/research-institute/api/v3/index.json

Copy to clipboard

> nuget.exe install JsonApiDotNetCore -Version 2.0.0-alpha1-0109 -Source https://www.myget.org/F/research-institute/api/v3/index.json

Copy to clipboard

> dotnet add package JsonApiDotNetCore --version 2.0.0-alpha1-0109 --source https://www.myget.org/F/research-institute/api/v3/index.json

Copy to clipboard
<PackageReference Include="JsonApiDotNetCore" Version="2.0.0-alpha1-0109" />
Copy to clipboard
source https://www.myget.org/F/research-institute/api/v3/index.json

nuget JsonApiDotNetCore  ~> 2.0.0-alpha1-0109
Copy to clipboard

> choco install JsonApiDotNetCore --version 2.0.0-alpha1-0109 --source https://www.myget.org/F/research-institute/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "research-institute" -SourceLocation "https://www.myget.org/F/research-institute/api/v2"
Install-Module -Name "JsonApiDotNetCore" -RequiredVersion "2.0.0-alpha1-0109" -Repository "research-institute" -AllowPreRelease
Copy to clipboard

JsonApiDotNetCore

Build Coverage NuGet GitHub License Chat FIRST-TIMERS

A framework for building JSON:API compliant REST APIs using ASP.NET Core and Entity Framework Core. Includes support for the Atomic Operations extension.

The ultimate goal of this library is to eliminate as much boilerplate as possible by offering out-of-the-box features, such as sorting, filtering, pagination, sparse fieldset selection, and side-loading related resources. You just need to focus on defining the resources and implementing your custom business logic. This library has been designed around dependency injection, making extensibility incredibly easy.

[!NOTE] OpenAPI support is now available, currently in preview. Give it a try!

Getting started

The following steps describe how to create a JSON:API project.

  1. Create a new ASP.NET Core Web API project:

    dotnet new webapi --no-openapi --use-controllers --name ExampleJsonApi
    cd ExampleJsonApi
    
  2. Install the JsonApiDotNetCore package, along with your preferred Entity Framework Core provider:

    dotnet add package JsonApiDotNetCore
    dotnet add package Microsoft.EntityFrameworkCore.Sqlite
    
  3. Declare your entities, annotated with JsonApiDotNetCore attributes:

    [Resource]
    public class Person : Identifiable<long>
    {
        [Attr] public string? FirstName { get; set; }
        [Attr] public string LastName { get; set; } = null!;
        [HasMany] public ISet<Person> Children { get; set; } = new HashSet<Person>();
    }
    
  4. Define your DbContext, seeding the database with sample data:

    public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
    {
        public DbSet<Person> People => Set<Person>();
    
        protected override void OnConfiguring(DbContextOptionsBuilder builder)
        {
            builder.UseSqlite("Data Source=SampleDb.db");
            builder.UseAsyncSeeding(async (dbContext, _, cancellationToken) =>
            {
                dbContext.Set<Person>().Add(new Person
                {
                    FirstName = "John",
                    LastName = "Doe",
                    Children =
                    {
                        new Person
                        {
                            FirstName = "Baby",
                            LastName = "Doe"
                        }
                    }
                });
                await dbContext.SaveChangesAsync(cancellationToken);
            });
        }
    }
    
  5. Configure Entity Framework Core and JsonApiDotNetCore in Program.cs:

    var builder = WebApplication.CreateBuilder(args);
    builder.Services.AddDbContext<AppDbContext>();
    builder.Services.AddJsonApi<AppDbContext>(options =>
    {
        options.UseRelativeLinks = true;
        options.IncludeTotalResourceCount = true;
    });
    
    var app = builder.Build();
    app.UseRouting();
    app.UseJsonApi();
    app.MapControllers();
    await CreateDatabaseAsync(app.Services);
    app.Run();
    
    static async Task CreateDatabaseAsync(IServiceProvider serviceProvider)
    {
        await using var scope = serviceProvider.CreateAsyncScope();
        var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
        await dbContext.Database.EnsureDeletedAsync();
        await dbContext.Database.EnsureCreatedAsync();
    }
    
  6. Start your API

    dotnet run
    
  7. Send a GET request to retrieve data:

    GET http://localhost:5000/people?filter=equals(firstName,'John')&include=children HTTP/1.1
    
    Expand to view the JSON response
    {
      "links": {
        "self": "/people?filter=equals(firstName,%27John%27)&include=children",
        "first": "/people?filter=equals(firstName,%27John%27)&include=children",
        "last": "/people?filter=equals(firstName,%27John%27)&include=children"
      },
      "data": [
        {
          "type": "people",
          "id": "1",
          "attributes": {
            "firstName": "John",
            "lastName": "Doe"
          },
          "relationships": {
            "children": {
              "links": {
                "self": "/people/1/relationships/children",
                "related": "/people/1/children"
              },
              "data": [
                {
                  "type": "people",
                  "id": "2"
                }
              ]
            }
          },
          "links": {
            "self": "/people/1"
          }
        }
      ],
      "included": [
        {
          "type": "people",
          "id": "2",
          "attributes": {
            "firstName": "Baby",
            "lastName": "Doe"
          },
          "relationships": {
            "children": {
              "links": {
                "self": "/people/2/relationships/children",
                "related": "/people/2/children"
              }
            }
          },
          "links": {
            "self": "/people/2"
          }
        }
      ],
      "meta": {
        "total": 1
      }
    }
    

Learn more

The following links explain what this project provides, why it exists, and how you can use it.

About

Official documentation

Samples

  • The examples directory provides ready-to-run sample API projects, which are documented here.
  • The integration tests directory covers many advanced use cases, which are documented here. This includes topics such as batching, multi-tenancy, authorization, soft-deletion, obfuscated IDs, resource inheritance, alternate routing, custom metadata, error handling and logging.
  • The Ember.js Todo List App showcases a JsonApiDotNetCore API and an Ember.js client with token authentication.

Related projects

Compatibility

The following chart should help you pick the best version, based on your environment. See also our versioning policy.

.NET Entity Framework Core JsonApiDotNetCore Status
10 10 5.10.0+ Stable
9 9 5.5.0+ Stable
8 8, 9 5.5.0+ Stable
7 7 5.0.3 - 5.6.0 Out of support
6 7 5.0.3 - 5.6.0 Out of support
6 6 5.0.0 - 5.6.0 Out of support
5 5 4.x Out of support
Core 3.1 3.1, 5 4.x Out of support
Core 2.x 2.x 3.x Out of support

Trying out the latest build

After each commit to the master branch, a new pre-release NuGet package is automatically published to feedz.io. To try it out, follow the steps below:

  1. Create a nuget.config file in the same directory as your .sln file, with the following contents:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <add key="json-api-dotnet" value="https://f.feedz.io/json-api-dotnet/jsonapidotnetcore/nuget/index.json" />
        <add key="NuGet" value="https://api.nuget.org/v3/index.json" />
      </packageSources>
    </configuration>
    
  2. In your IDE, browse the list of packages from the json-api-dotnet feed. Make sure pre-release packages are included in the list.

Contributing

Have a question, found a bug or want to submit code changes? See our contributing guidelines.

Build from source

To build the code from this repository locally, run:

dotnet build

Running tests locally requires access to a PostgreSQL database. If you have docker installed, this can be started via:

pwsh run-docker-postgres.ps1

And then to run the tests:

dotnet test

Alternatively, to build, run all tests, generate code coverage and NuGet packages:

pwsh Build.ps1

Sponsors

We are grateful to the following sponsors, who provide the team with a no-cost license for using their tools.

    Araxis Logo

Do you like this project? Consider to sponsor, or just reward us by giving our repository a star.

  • .NETCoreApp 1.0
    • Microsoft.AspNetCore.Mvc (>= 1.1.2)
    • Microsoft.AspNetCore.Routing (>= 1.1.1)
    • Microsoft.EntityFrameworkCore (>= 1.1.1)
    • Microsoft.Extensions.Logging (>= 1.1.1)
    • Microsoft.NETCore.App (>= 1.1.1)
    • System.ValueTuple (>= 4.3.0)
  • .NETCoreApp 1.0: 1.0.0.0

Owners

jaredcnance

Authors

JsonApiDotNetCore

Project URL

https://github.com/Research-Institute/json-api-dotnet-core

License

MIT

Tags

jsonapi dotnet core emberjs ember

Info

1291 total downloads
8 downloads for version 2.0.0-alpha1-0109
Download (41.5 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
4.0.0-alpha1-0367 166.03 KB Thu, 07 Nov 2019 17:43:31 GMT 10
4.0.0-alpha1-0366 166.04 KB Thu, 07 Nov 2019 17:40:31 GMT 9
4.0.0-alpha1-0365 166.08 KB Wed, 06 Nov 2019 17:36:30 GMT 9
4.0.0-alpha1-0364 166.08 KB Wed, 06 Nov 2019 17:33:44 GMT 8
4.0.0-alpha1-0363 166.08 KB Wed, 06 Nov 2019 17:27:16 GMT 10
4.0.0-alpha1-0362 166.07 KB Wed, 06 Nov 2019 17:23:57 GMT 8
4.0.0-alpha1-0361 166.09 KB Mon, 04 Nov 2019 16:39:18 GMT 10
4.0.0-alpha1-0360 166.09 KB Mon, 04 Nov 2019 16:35:52 GMT 7
4.0.0-alpha1-0359 166.78 KB Mon, 04 Nov 2019 11:13:29 GMT 8
4.0.0-alpha1-0358 166.78 KB Mon, 04 Nov 2019 11:10:36 GMT 9
4.0.0-alpha1-0357 166.79 KB Fri, 01 Nov 2019 16:01:03 GMT 5
4.0.0-alpha1-0356 166.78 KB Fri, 01 Nov 2019 15:58:20 GMT 8
4.0.0-alpha1-0355 166.75 KB Thu, 31 Oct 2019 09:47:48 GMT 9
4.0.0-alpha1-0354 166.75 KB Thu, 31 Oct 2019 09:45:15 GMT 11
4.0.0-alpha1-0353 166.86 KB Wed, 30 Oct 2019 19:36:38 GMT 10
4.0.0-alpha1-0352 166.86 KB Wed, 30 Oct 2019 19:33:57 GMT 8
4.0.0-alpha1-0351 166.87 KB Wed, 30 Oct 2019 16:46:48 GMT 10
4.0.0-alpha1-0350 166.87 KB Wed, 30 Oct 2019 16:43:50 GMT 10
4.0.0-alpha1-0349 166 KB Wed, 30 Oct 2019 16:40:46 GMT 9
4.0.0-alpha1-0348 166 KB Wed, 30 Oct 2019 16:36:01 GMT 9
3.0.0-alpha1-0209 121.39 KB Wed, 03 Oct 2018 14:52:04 GMT 10
3.0.0-alpha1-0204 114.26 KB Wed, 03 Oct 2018 04:57:35 GMT 9
3.0.0-alpha1-0203 114.26 KB Wed, 03 Oct 2018 04:54:51 GMT 10
2.4.1 100.53 KB Mon, 23 Jul 2018 06:07:33 GMT 10
2.4.0-alpha1-0138 100.57 KB Wed, 25 Jul 2018 06:54:16 GMT 10
2.4.0-alpha1-0137 100.58 KB Wed, 25 Jul 2018 06:49:25 GMT 8
2.4.0-alpha1-0133 99.41 KB Mon, 23 Jul 2018 05:41:42 GMT 9
2.4.0-alpha1-0127 99.27 KB Tue, 10 Jul 2018 03:02:53 GMT 8
2.3.5-alpha1-0125 99.29 KB Mon, 09 Jul 2018 21:28:53 GMT 10
2.3.5-alpha1-0124 99.02 KB Mon, 09 Jul 2018 14:31:00 GMT 12
2.3.5-alpha1-0122 98.95 KB Sat, 07 Jul 2018 01:38:25 GMT 8
2.3.5-alpha1-0121 98.97 KB Sat, 07 Jul 2018 01:27:48 GMT 9
2.3.5-alpha1-0119 98.86 KB Sat, 07 Jul 2018 01:20:53 GMT 10
2.3.5-alpha1-0117 98.85 KB Thu, 05 Jul 2018 18:16:26 GMT 12
2.3.4-alpha1-0113 98.86 KB Thu, 05 Jul 2018 02:36:48 GMT 11
2.3.4-alpha1-0112 98.87 KB Thu, 05 Jul 2018 02:28:41 GMT 10
2.3.4-alpha1-0111 98.68 KB Tue, 03 Jul 2018 15:47:54 GMT 12
2.3.4-alpha1-0110 75.31 KB Tue, 03 Jul 2018 15:44:41 GMT 8
2.3.4-alpha1-0109 73.42 KB Mon, 02 Jul 2018 17:19:22 GMT 10
2.3.2-alpha1-0103 72.68 KB Wed, 27 Jun 2018 22:20:56 GMT 11
2.3.2-alpha1-0101 70.98 KB Mon, 18 Jun 2018 17:25:48 GMT 7
2.3.1-alpha1-0100 70.82 KB Mon, 18 Jun 2018 17:19:18 GMT 9
2.2.5-alpha1-0086 70.19 KB Sat, 09 Jun 2018 04:25:02 GMT 8
2.2.2-alpha1-0075 67.44 KB Sat, 28 Apr 2018 12:32:39 GMT 8
2.2.2-alpha1-0074 66.43 KB Sat, 28 Apr 2018 12:29:38 GMT 9
2.2.2-alpha1-0071 66.36 KB Sun, 22 Apr 2018 13:00:46 GMT 7
2.2.0-alpha1-0060 62.32 KB Fri, 02 Mar 2018 13:19:07 GMT 10
2.2.0-alpha1-0059 62.47 KB Thu, 01 Mar 2018 12:38:15 GMT 9
2.2.0-alpha1-0054 62.92 KB Sun, 18 Feb 2018 16:39:23 GMT 9
2.2.0-alpha1-0021 60.57 KB Mon, 13 Nov 2017 02:45:20 GMT 6
2.1.7-alpha1-0011 59.86 KB Tue, 24 Oct 2017 11:56:38 GMT 9
2.1.6-alpha1-0010 59.77 KB Tue, 24 Oct 2017 11:54:55 GMT 12
2.1.5-alpha1-0007 50.9 KB Wed, 27 Sep 2017 00:59:22 GMT 10
2.1.4-alpha1-0220 50.89 KB Sun, 17 Sep 2017 19:53:51 GMT 10
2.1.3-alpha1-0217 50.86 KB Thu, 17 Aug 2017 01:56:23 GMT 9
2.1.2-alpha1-0211 50.81 KB Thu, 10 Aug 2017 00:11:16 GMT 11
2.1.1-alpha1-0209 50.81 KB Fri, 28 Jul 2017 20:54:06 GMT 8
2.1.0-alpha1-0200 50.79 KB Sun, 02 Jul 2017 22:40:37 GMT 8
2.1.0-alpha1-0199 50.79 KB Sun, 02 Jul 2017 22:06:37 GMT 11
2.1.0-alpha1-0197 50.43 KB Sun, 02 Jul 2017 20:12:51 GMT 11
2.0.9-alpha1-0183 43.41 KB Wed, 14 Jun 2017 16:56:59 GMT 8
2.0.8-alpha1-0174 43.37 KB Fri, 02 Jun 2017 00:32:57 GMT 9
2.0.8-alpha1-0173 42.65 KB Thu, 01 Jun 2017 03:22:26 GMT 7
2.0.8-alpha1-0172 42.58 KB Wed, 31 May 2017 12:02:51 GMT 9
2.0.8-alpha1-0171 42.33 KB Wed, 31 May 2017 03:37:46 GMT 12
2.0.7-alpha1-0168 42.25 KB Sat, 27 May 2017 13:34:33 GMT 11
2.0.7-alpha1-0167 41.97 KB Sat, 27 May 2017 00:09:59 GMT 11
2.0.6-alpha1-0166 41.96 KB Sat, 27 May 2017 00:05:24 GMT 11
2.0.6-alpha1-0163 41.94 KB Tue, 16 May 2017 14:03:40 GMT 12
2.0.5-alpha1-0158 42.11 KB Sun, 14 May 2017 03:15:20 GMT 10
2.0.2-alpha1-0124 41.51 KB Thu, 11 May 2017 22:18:20 GMT 10
2.0.2-alpha1-0119 41.51 KB Tue, 09 May 2017 20:31:15 GMT 9
2.0.2-alpha1-0118 41.52 KB Tue, 09 May 2017 20:15:27 GMT 9
2.0.1-alpha1-0114 41.52 KB Sat, 06 May 2017 15:01:33 GMT 10
2.0.0-alpha1-0110 41.5 KB Sat, 06 May 2017 01:11:04 GMT 13
2.0.0-alpha1-0109 41.5 KB Fri, 05 May 2017 23:10:43 GMT 8
2.0.0-alpha1-0108 41.62 KB Thu, 27 Apr 2017 21:47:42 GMT 11
2.0.0-alpha1-0107 41.52 KB Wed, 26 Apr 2017 22:57:28 GMT 10
2.0.0-alpha1-0106 41.53 KB Tue, 25 Apr 2017 15:09:29 GMT 13
1.3.1-alpha1-0103 38.68 KB Wed, 12 Apr 2017 12:52:40 GMT 12
1.3.1-alpha1-0102 38.7 KB Tue, 11 Apr 2017 13:31:03 GMT 10
1.3.1-alpha1-0100 37.95 KB Sun, 09 Apr 2017 15:49:07 GMT 13
1.3.1-alpha1-0099 37.95 KB Sun, 09 Apr 2017 15:47:41 GMT 13
1.3.0-alpha1-0096 37.87 KB Fri, 31 Mar 2017 14:36:54 GMT 11
1.3.0-alpha1-0095 37.87 KB Fri, 31 Mar 2017 00:03:45 GMT 8
1.3.0-alpha1-0094 37.87 KB Thu, 30 Mar 2017 11:52:53 GMT 13
1.3.0-alpha1-0093 37.77 KB Thu, 30 Mar 2017 02:36:33 GMT 13
1.3.0-alpha1-0092 37.77 KB Thu, 30 Mar 2017 01:13:28 GMT 9
1.2.2-alpha1-0088 37.32 KB Sat, 25 Mar 2017 02:10:11 GMT 9
1.2.2-alpha1-0087 37.27 KB Thu, 23 Mar 2017 23:18:32 GMT 9
1.2.1-alpha1-0086 37.22 KB Thu, 23 Mar 2017 23:11:37 GMT 8
1.2.0-alpha1-0081 37.14 KB Tue, 21 Mar 2017 13:54:12 GMT 12
1.2.0-alpha1-0080 37.14 KB Tue, 21 Mar 2017 13:16:53 GMT 11
1.2.0-alpha1-0079 36.28 KB Mon, 20 Mar 2017 21:23:07 GMT 13
1.2.0-alpha1-0078 36.28 KB Mon, 20 Mar 2017 21:21:44 GMT 7
1.2.0-alpha1-0077 35.88 KB Mon, 20 Mar 2017 20:08:45 GMT 13
1.2.0-alpha1-0076 35.84 KB Mon, 20 Mar 2017 19:22:45 GMT 12
1.2.0-alpha1-0073 35.43 KB Fri, 17 Mar 2017 13:46:28 GMT 11
1.1.1-alpha1-0070 33.87 KB Thu, 16 Mar 2017 01:42:18 GMT 9
1.1.1-alpha1-0069 33.8 KB Wed, 15 Mar 2017 22:21:30 GMT 9
1.1.0 33.19 KB Tue, 14 Mar 2017 15:22:20 GMT 11
1.1.0-alpha1-0068 33.8 KB Wed, 15 Mar 2017 22:19:07 GMT 11
1.0.1 31.7 KB Tue, 14 Mar 2017 12:52:35 GMT 10
1.0.0 31.67 KB Thu, 02 Mar 2017 14:15:47 GMT 8
1.0.0-beta2-0045 31.69 KB Thu, 02 Mar 2017 14:12:18 GMT 11
1.0.0-beta2-0044 31.69 KB Thu, 02 Mar 2017 13:11:57 GMT 12
1.0.0-beta2-0043 31.58 KB Thu, 02 Mar 2017 12:29:35 GMT 12
1.0.0-beta1-0042 31.71 KB Wed, 01 Mar 2017 22:56:21 GMT 8
1.0.0-beta1-0041 29.59 KB Wed, 01 Mar 2017 14:44:36 GMT 14
1.0.0-beta1-0040 29.58 KB Wed, 01 Mar 2017 14:35:10 GMT 11
0.2.12 28.22 KB Sat, 25 Feb 2017 16:29:26 GMT 11
0.2.11 27.73 KB Wed, 22 Feb 2017 15:12:44 GMT 17
0.2.10 27.26 KB Tue, 21 Feb 2017 23:32:03 GMT 11
0.2.9 27.21 KB Mon, 20 Feb 2017 15:30:35 GMT 13
0.2.8 26.25 KB Mon, 13 Feb 2017 13:31:52 GMT 11
0.1.4 37.02 KB Fri, 09 Sep 2016 15:49:56 GMT 12
0.1.4-beta-0016 37.06 KB Fri, 09 Sep 2016 15:40:38 GMT 11
0.1.4-beta-0015 37.06 KB Fri, 09 Sep 2016 15:21:17 GMT 9
0.1.4-beta-0014 37.07 KB Fri, 09 Sep 2016 15:15:20 GMT 15
0.1.4-beta-0013 37.06 KB Fri, 09 Sep 2016 15:12:18 GMT 14
0.1.4-beta-0012 37.06 KB Thu, 08 Sep 2016 17:18:32 GMT 16
0.1.4-beta-0011 36.95 KB Fri, 02 Sep 2016 19:58:41 GMT 12
0.1.3 34.96 KB Fri, 02 Sep 2016 02:16:31 GMT 10
0.1.2 34.96 KB Fri, 02 Sep 2016 02:10:41 GMT 14
0.1.1 34.54 KB Thu, 01 Sep 2016 21:32:29 GMT 12
0.1.0-alpha-0002 34.19 KB Wed, 31 Aug 2016 18:39:24 GMT 13
0.1.0-alpha-0001 34.19 KB Wed, 31 Aug 2016 18:26:46 GMT 9