<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>JSON:API in .NET on Yunier&#39;s Wiki</title>
    <link>http://localhost:1313/series/jsonapi-in-.net/</link>
    <description>Recent content in JSON:API in .NET on Yunier&#39;s Wiki</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Sun, 15 Oct 2023 00:00:00 +0000</lastBuildDate>
    <atom:link href="http://localhost:1313/series/jsonapi-in-.net/rss" rel="self" type="application/rss+xml" />
    <item>
      <title>JSON:API Implementing Filtering</title>
      <link>http://localhost:1313/post/2023/json-api-implementing-filtering/</link>
      <pubDate>Sun, 15 Oct 2023 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2023/json-api-implementing-filtering/</guid>
      <description>&lt;h3 id=&#34;introduction&#34;&gt;Introduction&lt;/h3&gt;&#xA;&lt;p&gt;It has been over &lt;a href=&#34;http://localhost:1313/post/2022/json-api-pagination-links/&#34;&gt;a year since I last wrote&lt;/a&gt; about JSON:API, since then the &lt;a href=&#34;https://jsonapi.org/about/#editors&#34;&gt;team&lt;/a&gt; behind JSON:API has published version 1.1 of the JSON:API specification. I would like to continue my journey of documenting JOSN:API in .NET by introducing a really cool feature to my &lt;a href=&#34;https://github.com/circleupx/Chinook&#34;&gt;Chinook JSON:API&lt;/a&gt; project, filtering.&lt;/p&gt;&#xA;&lt;p&gt;The first thing to know about filtering in JSON:API is that the spec itself &lt;a href=&#34;https://jsonapi.org/format/#fetching-filtering&#34;&gt;is agnostic&lt;/a&gt; to any filtering strategies. Meaning it is up to you to define how filtering should be handled by your API. In my opinion, this has always been a drawback of the JSON:API spec, I believe in that it would have been a better choice for the spec if it had decided on a filtering strategy, but that is discussion for another day. While the spec does not favor any filtering strategy it does have some &lt;a href=&#34;https://jsonapi.org/recommendations/#filtering&#34;&gt;recommendations&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>JSON:API - Pagination Links</title>
      <link>http://localhost:1313/post/2022/json-api-pagination-links/</link>
      <pubDate>Tue, 25 Jan 2022 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2022/json-api-pagination-links/</guid>
      <description>&lt;p&gt;It has been a while since I blogged about &lt;a href=&#34;https://jsonapi.org/&#34;&gt;JSON:API&lt;/a&gt;. In my last post on JSON:API I covered how to create &lt;a href=&#34;http://localhost:1313/post/2021/json-api-creating-new-resources/&#34;&gt;new resources&lt;/a&gt;. In today&amp;rsquo;s post, I want to go over how I expose pagination links. &lt;a href=&#34;https://jsonapi.org/examples/#pagination&#34;&gt;Pagination links&lt;/a&gt; allow a client to page through a collection of resources. A shift of control from the client back to the server.&lt;/p&gt;&#xA;&lt;p&gt;Here is an example of a possible JSON:API response that includes pagination links.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 5&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 6&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 7&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 8&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 9&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt;10&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt;11&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt;12&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt;13&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt;14&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt;15&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-json&#34; data-lang=&#34;json&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#f92672&#34;&gt;&amp;#34;data&amp;#34;&lt;/span&gt;: [&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;color:#75715e&#34;&gt;// omitted for brevity&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&lt;/span&gt;    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  ],&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#f92672&#34;&gt;&amp;#34;links&amp;#34;&lt;/span&gt;: {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;&amp;#34;up&amp;#34;&lt;/span&gt;: &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;http://example.com/&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;&amp;#34;self&amp;#34;&lt;/span&gt;: &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;http://example.com/articles?page[number]=3&amp;amp;page[size]=1&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;&amp;#34;first&amp;#34;&lt;/span&gt;: &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;http://example.com/articles?page[number]=1&amp;amp;page[size]=1&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;&amp;#34;prev&amp;#34;&lt;/span&gt;: &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;http://example.com/articles?page[number]=2&amp;amp;page[size]=1&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;&amp;#34;next&amp;#34;&lt;/span&gt;: &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;http://example.com/articles?page[number]=4&amp;amp;page[size]=1&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;&amp;#34;last&amp;#34;&lt;/span&gt;: &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;http://example.com/articles?page[number]=13&amp;amp;page[size]=1&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;p&gt;As you can see, along with the &lt;a href=&#34;https://jsonapi.org/format/#document-top-level&#34;&gt;data&lt;/a&gt; object, the API responses included a &lt;a href=&#34;https://jsonapi.org/format/#document-links&#34;&gt;Links&lt;/a&gt; object, within the Links object, you can find links for up, self, first, prev, next, and last. These are all relationship name as defined in &lt;a href=&#34;https://www.iana.org/assignments/link-relations/link-relations.xhtml&#34;&gt;Link Relations&lt;/a&gt; by the Internet Assigned Numbers Authority (IANA).&lt;/p&gt;</description>
    </item>
    <item>
      <title>JSON:API - Creating New Resources</title>
      <link>http://localhost:1313/post/2021/json-api-creating-new-resources/</link>
      <pubDate>Sun, 08 Aug 2021 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2021/json-api-creating-new-resources/</guid>
      <description>&lt;p&gt;So far in my JSON:API series I&amp;rsquo;ve covered the &lt;a href=&#34;https://www.yunier.dev/2020-09-14-Adding-Home-Resource/&#34;&gt;home resource&lt;/a&gt;, adding &lt;a href=&#34;https://www.yunier.dev/2020-10-30-Adding-Customer-Resource/&#34;&gt;your own resource&lt;/a&gt;, adding an &lt;a href=&#34;https://www.yunier.dev/2020-10-19-Exception-Handling-Middleware/&#34;&gt;exception handling middleware&lt;/a&gt; and how to &lt;a href=&#34;https://www.yunier.dev/2020-12-06-Exposing-Relationships/&#34;&gt;expose relationship&lt;/a&gt; between resources. For the today&amp;rsquo;s post, I would like to cover creating resources. I will update the chinook project by allowing &lt;a href=&#34;https://datatracker.ietf.org/doc/html/rfc2616/#section-9.5&#34;&gt;POST&lt;/a&gt; request on the customers collections to add new customers.&lt;/p&gt;&#xA;&lt;p&gt;To get started, the customer controller needs to have a method that will accept the incoming POST request. I&amp;rsquo;ve decided to call the method &lt;strong&gt;CreateCustomerResource&lt;/strong&gt;, the method will accept a &lt;a href=&#34;https://jsonapi.org/format/#document-structure&#34;&gt;JSON:API document&lt;/a&gt; from the request body. The full method signature is defined below.&lt;/p&gt;</description>
    </item>
    <item>
      <title>JSON:API - Exposing Relationships</title>
      <link>http://localhost:1313/post/2020/json-api-exposing-relationships/</link>
      <pubDate>Sun, 06 Dec 2020 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2020/json-api-exposing-relationships/</guid>
      <description>&lt;p&gt;My &lt;a href=&#34;http://localhost:1313/post/2020/json-api-exposing-the-customer-resource/&#34;&gt;previous&lt;/a&gt; post on JSON:API exposed customers as an API resource, since then, I have updated the project to expose all remaining resources, that includes  Albums, Artists, Employees, Genres, Invoices, InvoiceItems, MediaTypes, Playlists, and Tracks. The time has come to expose the relationship that exist between these resource.&lt;/p&gt;&#xA;&lt;p&gt;For this post, I will expose the one-to-many relationship that exist between artists and albums. To accomplish this task I will have to update the class ArtistServiceModelConfiguration by using the ToManyRelationship method exposed by JsonApiFramework in order to link one artist to many albums.&lt;/p&gt;</description>
    </item>
    <item>
      <title>JSON:API - Exposing The Customer Resource</title>
      <link>http://localhost:1313/post/2020/json-api-exposing-the-customer-resource/</link>
      <pubDate>Fri, 30 Oct 2020 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2020/json-api-exposing-the-customer-resource/</guid>
      <description>&lt;p&gt;This will be my third blog post on &lt;a href=&#34;https://jsonapi.org/&#34;&gt;JSON:API&lt;/a&gt; in .NET Core.&lt;/p&gt;&#xA;&lt;p&gt;I plant to add &lt;strong&gt;Customer&lt;/strong&gt; as an API resource, but before we get too deep on the code, I would like to review the &lt;a href=&#34;https://www.sqlitetutorial.net/sqlite-sample-database/&#34;&gt;Chinook&lt;/a&gt; database project. To do that I&amp;rsquo;m going to import &lt;a href=&#34;https://cdn.sqlitetutorial.net/wp-content/uploads/2018/03/chinook.zip&#34;&gt;Chinook.db&lt;/a&gt; into &lt;a href=&#34;https://sqlitebrowser.org/dl/&#34;&gt;DB Browser&lt;/a&gt; for SQLite to see all available entities.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img loading=&#34;lazy&#34; src=&#34;http://localhost:1313/post/2020/json-api-exposing-the-customer-resource/chinook-database-entities.PNG&#34; alt=&#34;Database Entities&#34;  /&gt;&#xD;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;As you can see we have quite a few entities, for this blog post I will concentrate on the &lt;strong&gt;customers&lt;/strong&gt; entity. To accomplish adding customers as an API resource I will need to create a new service model that represents the customers entity in both JsonApiFramework and EF Core. I will scaffold the SQLite database using &lt;a href=&#34;https://docs.microsoft.com/en-us/ef/core/managing-schemas/scaffolding?tabs=dotnet-core-cli&#34;&gt;EF Core&amp;rsquo;s reverse engineering capabilities&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>JSON:API - Exception Handling Middleware</title>
      <link>http://localhost:1313/post/2020/json-api-exception-handling-middleware/</link>
      <pubDate>Mon, 19 Oct 2020 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2020/json-api-exception-handling-middleware/</guid>
      <description>&lt;p&gt;On my second post on &lt;a href=&#34;https://jsonapi.org/&#34;&gt;JSON:API&lt;/a&gt; in .NET Core I wanted to create an exception handling &lt;a href=&#34;https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-3.1&#34;&gt;middleware&lt;/a&gt;. This middleware would be responsible for catching all exceptions and for generating a JSON:API &lt;a href=&#34;https://jsonapi.org/format/#document-top-level&#34;&gt;Errors Documents&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I&amp;rsquo;ll start by adding a middleware folder on the Chinook.Web project, for now it will only have the exception handling middleware, but, eventually it will have additional middleware.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img loading=&#34;lazy&#34; src=&#34;http://localhost:1313/post/2020/json-api-exception-handling-middleware/middleware-folder.PNG&#34; alt=&#34;Middleware Folder&#34;  /&gt;&#xD;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Folder has been added, now I will add the middleware class to the project in here.&lt;/p&gt;</description>
    </item>
    <item>
      <title>JSON:API - Creating The Home Resource</title>
      <link>http://localhost:1313/post/2020/json-api-creating-the-home-resource/</link>
      <pubDate>Mon, 14 Sep 2020 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2020/json-api-creating-the-home-resource/</guid>
      <description>&lt;p&gt;This post will be my first entry into a multi-part series of post showing how I&amp;rsquo;ve built RESTful APIs using the &lt;a href=&#34;https://jsonapi.org/&#34;&gt;JSON:API&lt;/a&gt; specification on .NET Core.&lt;/p&gt;&#xA;&lt;p&gt;I will start by creating a new .NET Core Web Api project, I am going to call this project &lt;strong&gt;Chinook&lt;/strong&gt;, after the sqlite &lt;a href=&#34;https://www.sqlitetutorial.net/sqlite-sample-database/&#34;&gt;database&lt;/a&gt; that I will use for this project. Whenever I create a .NET Core project I like to follow the project structure outlined by Steve Smith in his &lt;a href=&#34;https://github.com/ardalis/CleanArchitecture&#34;&gt;Clean Architecture&lt;/a&gt; repository.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
