<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: raisr</title>
    <description>The latest articles on DEV Community by raisr (@raisr).</description>
    <link>https://dev.to/raisr</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F657994%2F4ab3fade-f2d2-4fc0-be59-c97491f70dbb.jpeg</url>
      <title>DEV Community: raisr</title>
      <link>https://dev.to/raisr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/raisr"/>
    <language>en</language>
    <item>
      <title>API Framework, the moving parts</title>
      <dc:creator>raisr</dc:creator>
      <pubDate>Thu, 11 Nov 2021 21:55:19 +0000</pubDate>
      <link>https://dev.to/raisr/api-framework-the-moving-parts-4p56</link>
      <guid>https://dev.to/raisr/api-framework-the-moving-parts-4p56</guid>
      <description>&lt;p&gt;In my last post "&lt;a href="https://dev.to/raisr/starting-my-api-journey-32an"&gt;Starting my API journey...&lt;/a&gt;" i wrote about my plans to create a framework that eases the development of web APIs.&lt;/p&gt;

&lt;p&gt;In this post i'm going to outline my current ideas about the parts the framework should include and how they relate to each other. &lt;/p&gt;

&lt;p&gt;So what parts should an API framework include? Of course, my ideas are very opinionated. But this are the parts that always made my life as a developer hard.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gateway
&lt;/h2&gt;

&lt;p&gt;The gateway acts as a reverse proxy that builds the boundary between the clients and our services. When a client calls an endpoint the gateway redirects the call to an internal service and returns the response. If desired it can provide additional features that so that we don't need to implement them in our services.&lt;/p&gt;

&lt;p&gt;Possible additional features are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Throttling&lt;/li&gt;
&lt;li&gt;Authentication / Authorization (using an identity provider)&lt;/li&gt;
&lt;li&gt;SSL Termination&lt;/li&gt;
&lt;li&gt;Analytics (using a telemetry service) &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In my framework i will use &lt;a href="https://github.com/microsoft/reverse-proxy"&gt;YARP&lt;/a&gt;. Yarp is an open source reverse proxy built by microsoft. You can read a short summary about YARP in the &lt;a href="https://devblogs.microsoft.com/dotnet/announcing-yarp-1-0-release/"&gt;announcement post&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Logging / Telemetry
&lt;/h2&gt;

&lt;p&gt;Logging, telemetry and analytics are an important part for every API. Identifying problems and bottlenecks early is important to keep our customers happy and the system healthy. The telemetry service should handle task like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Storing and analyzing logs / errors&lt;/li&gt;
&lt;li&gt;Provide usage statistics, execution times, etc. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the logging part i will use &lt;a href="https://serilog.net/"&gt;serilog&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Identity Provider
&lt;/h2&gt;

&lt;p&gt;The most APIs need some kind of authentication / authorization. Unfortunately this is one of the hardest parts. There are a lot of libraries / frameworks out there to do this. But either they are not able to handle multi tenancy or they are very complex. And mostly you need to have more security know how than you want. I want to provide a security solution that is easy to use and provides a lot of features. I think this will be the hardest part in my framework. &lt;/p&gt;

&lt;p&gt;I want this part to provide the following features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OAuth2 / OpenID Connect workflows&lt;/li&gt;
&lt;li&gt;API Key Authentication&lt;/li&gt;
&lt;li&gt;Session based authentication (so that we can use it for simple websites)&lt;/li&gt;
&lt;li&gt;Multi tenancy support (one user can have different credentials for different APIs)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The biggest problem here is that there is no real open source solution that could provide this features. Microsoft does not provide something good. There is ASP.Net Identity with no support for OAuth and multi tenancy. So i guess i will go for &lt;a href="https://duendesoftware.com/products/identityserver"&gt;Duende Identity Server&lt;/a&gt;. It's not really free, but open source projects und small companies will not have to pay for it. It is really sad that there is no really open source alternative in the .Net world like &lt;a href="https://www.keycloak.org/"&gt;Keycloak&lt;/a&gt; in the java world. If you know an alternative just leave me a comment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Task Scheduling
&lt;/h2&gt;

&lt;p&gt;Task scheduling isn't really a crucial part of an API framework but it can make your life very convenient. Often you need to run tasks on a regular basis. Then you start creating shell scripts, batch files, etc. that you trigger by the windows task scheduler or linux cron jobs. It is far more convenient to trigger an API endpoint on a schedule. &lt;/p&gt;

&lt;p&gt;For this part i will use &lt;a href="https://www.hangfire.io/"&gt;hangfire&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuration
&lt;/h2&gt;

&lt;p&gt;We have to deal with a lot of configuration settings in our projects. Usually we store stuff in the configuration files of our APIs (web.config, appsettings.json, etc.) or in some database tables. Using config files has the disadvantage of redeploying our services when settings change. Storing the stuff in the database of our services clutters everything. The goal is to provide a central configuration system that you can use. Currently i have no idea which library i can use. Maybe you have some ideas. &lt;/p&gt;

&lt;h2&gt;
  
  
  Common UI
&lt;/h2&gt;

&lt;p&gt;All the features are very nice. But we want to view logs and telemetry data. We want to configure the gateway, identity provider and all the other parts. Of course we can do this by editing database tables or config files by hand. Ok, no! There should be a UI where we can do all this stuff. For this i want to create a Blazor SPA that provides a UI to do all this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next stop
&lt;/h2&gt;

&lt;p&gt;So whats next? Until now i didn't talk about naming. One of the hardest parts in software development :). I will think about some name and then create an initial github or gitlab repo. &lt;/p&gt;

&lt;p&gt;After that the first thing i will implement will be a simple gateway and telemetry (logging first) solution.&lt;/p&gt;




&lt;p&gt;&lt;sup&gt;Photo by &lt;a href="https://www.flickr.com/photos/thomashawk/"&gt;Thomas Hawk&lt;/a&gt;. License &lt;a href="https://creativecommons.org/licenses/by-nc/2.0/"&gt;CC BY-NC 2.0&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>webapi</category>
      <category>microservices</category>
      <category>csharp</category>
    </item>
    <item>
      <title>Starting my API journey...</title>
      <dc:creator>raisr</dc:creator>
      <pubDate>Fri, 29 Oct 2021 10:25:56 +0000</pubDate>
      <link>https://dev.to/raisr/starting-my-api-journey-32an</link>
      <guid>https://dev.to/raisr/starting-my-api-journey-32an</guid>
      <description>&lt;p&gt;During my career i mostly worked in small to medium companies. In most of them i had to create some kind of web based apis for a lot of different use cases. Being it as a backend for SPAs, public facing apis for customers and so on. Creating a simple rest api using the asp.net stack is quite simple. But very soon you have to tackle a lot more complicated / sophisticated problems like Authentication, load balancing, routing, configuration management, scheduled tasks and so on. &lt;/p&gt;

&lt;p&gt;There are a lot of free and or open source tools, libraries and frameworks that help you to solve those problems. But then the real challenge starts. The available solutions a often very powerful, written in different languages and require some effort to get started with. So you have to integrate them, manage the deployment / hosting on different OSes and keep all of this up to date. That is extremely challenging for a small to medium company. You just don't have all the skills on your team or the time and budget.&lt;/p&gt;

&lt;p&gt;So, what can i do? I want to create yet another framework :) &lt;/p&gt;

&lt;p&gt;No, i don't want to reinvent the wheel. My goal is to create some kind of framework that incorporates existing tools where possible and hides the magic behind but gives you the power to extend if required. In the end you should have everything at hand to create apis that provide your business value without havening to much to care about the rest of the infrastructure.&lt;/p&gt;

&lt;p&gt;So what does that mean. Lets say you want to have a logging solution. Then you could just do something like this pseudo code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;   &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UseLoggingServer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Enable logging server on this machine&lt;/span&gt;
   &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UseLogging&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"logging server uri"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//Send logs to the logging server&lt;/span&gt;
   &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UseLoggingUI&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Provide some ui to show the logs&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Under the hood it could use for example serilog. This code would configure serilog with settings that should be sufficient in most cases. But if not you could change the serilog configuration directly.&lt;/p&gt;

&lt;p&gt;These are some of the key aspects that i want the framework to follow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Modular&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cherrypick what you want. Just need an api gateway or logging? Pick this from the framework.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scalable&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It should be possible to run everything within a single web application or scale out stuff that is hitting the limits. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No rules for your code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The framework should handle the infrastructure stuff. It should not force you how to write your code in any way. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OS agnostic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The whole framework has to run on windows, linux, mac os.&lt;/p&gt;

&lt;p&gt;Here my journey starts...&lt;/p&gt;




&lt;p&gt;&lt;sup&gt;Photo by &lt;a href="https://unsplash.com/@clemensvanlay"&gt;Clemens van Lay&lt;/a&gt; on &lt;a href="https://unsplash.com/"&gt;Unsplash&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>webapi</category>
      <category>microservices</category>
      <category>csharp</category>
    </item>
  </channel>
</rss>
