Mike Kistler (Microsoft) on OpenAPI

OpenAPI is the framework of choice for documenting APIs


OpenAPI support in ASP.NET Core API apps
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/overview?view=aspnetcore-9.0
 
Generate OpenAPI documents at build-time
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/aspnetcore-openapi?view=aspnetcore-9.0&tabs=visual-studio%2Cvisual-studio-code#generate-openapi-documents-at-build-time
 
The project file property to set the directory where the OpenAPI should be saved is “OpenApiDocumentsDirectory” and it is documented here:
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/aspnetcore-openapi?view=aspnetcore-9.0&tabs=visual-studio%2Cvisual-studio-code#modifying-the-output-directory-of-the-generated-open-api-file
 
This section contains a summary of how C# types and attributes map to OpenAPI schemas.
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/include-metadata?view=aspnetcore-9.0&tabs=minimal-apis#include-openapi-metadata-for-data-types
 
We talked about the OpenAPI specification — the latest version is here:
https://spec.openapis.org/oas/v3.1.1.html
 
I also briefly touched on the Overlay specification — that is here:
https://spec.openapis.org/overlay/v1.0.0.html
 
and the Arazzo Specification — that is here:
https://spec.openapis.org/arazzo/v1.0.1.html
 
The Roadmap for ASP.NET Core features in .NET 10 is here:
https://github.com/dotnet/aspnetcore/issues/59443

 

Posted in API | Tagged | 11 Comments

Claude

There’s a new AI kid on the block (https://claude.ai) and he is very powerful for programming and many other things. At the risk of being obnoxious, here is what he said about me:

Jesse Liberty is a well-known software developer, author, and educator in the computer programming and software development world. He has written numerous books on programming languages and technologies, particularly focusing on C++, C#, and .NET development.

Continue reading
Posted in AI | 72 Comments

APIs with C# – Part 4 Options

NET provides support for passing options via environment variables, appsettings.json, and XML files. as well as command line arguments. In short, each higher level overrides the settings in lower levels.

To add options:

  1. Create a public class and name it (we’ll use funcOptions)
  2. Add a string property called returnValue (or name it whatever you like) and set the property to some value (e.g., MyOptions)
  3. We’re going to override that value in applications.json
  4. Add a property in appsettings.json (e.g., retVal) and set that property to a different value than we did in step 2

It’s time to set up the startup configuration. When you are done, your Program.cs should look like this:

var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureServices((context, services) =>
{
  services.AddApplicationInsightsTelemetryWorkerService()
  .ConfigureFunctionsApplicationInsights()
  .AddOptions<MyOptions>
     .BindConfiguration("");
})
.Build();
host.Run();

The next step is to inject IOptions<MyOptions> and in the constructor set a member variable.

The Run method will look like this:

[Function("Function1")]
public IActionResult Run(HttpTrigger(AuthorizationLevel
  .Anonymous, "get", "post")] HttpRequest req)
{
   return new OKObjectResult(options.value.retValue);
}

 

Posted in APIs | Leave a comment

144,000 users

My site says we just crossed 144,000 users. I’m stunned.

Posted in Essentials | 35 Comments

Turn the tables: 2016

Episode 50: The Technical Journey of Jesse Liberty

 

Episode 51: The Technical Wisdom of Jesse Liberty

Posted in Essentials | 2 Comments

API – Functions Part 3: Routing

In the previous part of this series, we looked at creating our first API. But how do you determine which API is being invoked? This is accomplished with routing.

If you have a Products class your entry (end point) might look like this:

[Function(nameof(Products))]
public IActionResult Run(HttpTrigger(AuthorizationLevel.Anonymous,
"get", Route="products/{category}/{id: int}")]
HttpRequest req, string category, int id)
{
  return new OkObjectResult(new {category, id});
}

Notice the routing property (“products/{category}/{id: int}” — this allows us to customize and restrict the arguments from the desired endpoint. The customer/user can now use the same endpoint for a variety of situations.

Continue reading

Posted in API, APIs, Essentials, Mini-Tutorial | Tagged | 1 Comment

API Part 2 – Creating An Azure Function

This is part 2 in our series on .NET APIs with C# – Functions. Find Part 1 here.

In this part we’ll talk about how you build an Azure Function. Functions are another way of interacting with an API. Here we’ll briefly discuss how you can get started with them.

  • Name your function, choose a location and click Next
  • Select your runtime and hosting. Generally speaking, choose the latest LTS (Long Term Support) option
  • Under authorization, choose Anonymous
  • Under Function, select Http trigger
  • Check Use Azurite (we’ll need this in a future post about durable functions)
  • Click next and hey presto! your solution is created.

Continue reading

Posted in API, APIs, Essentials, Mini-Tutorial | Tagged | Leave a comment

James Montemagno on blending .NET application development

A fascinating discussion of building .Net MAUI applications with Blazor and JavaScript libraries. James’ enthusiasm is catching and he doesn’t disappoint in this interview.

 

 

 

 

 

 

 

Posted in .NET MAUI, Angular, Blazor Hybrid, Community, Essentials, JavaScript | Tagged | 2 Comments

Azure Functions – Part 1

This begins a short series on Azure Functions and Durable Functions from the perspective of building APIs. This is based on material from my book Programming APIs with C# and .NET that I wrote with Joseph Dluzen (to tell the truth, the Functions chapters were initially written by Joe!)

Understanding Functions – Don’t Panic

Azure Functions are very important when focusing on event-driven data processing. Functions allow for ease of development, deployment and scaling. Functions are considered to be serverless in that you don’t have to manage individual instances.

Continue reading

Posted in API, Azure | 9 Comments

Mads K. on Visual Studio

Mads Kristensen discusses Visual Studio extensions, and the use of CoPilot to get the most out of Visual Studio programming.

Posted in Essentials, Visual Studio | Tagged | 4 Comments

Maddy Leger on Aspire

Maddy is the program manager/ owner of Microsoft’s Aspire. This is new, exciting and powerful.

More about Aspire

Posted in Aspire | Tagged | 8 Comments

Best of JesseLiberty.com: Bayesian Probability

This from 2009:

Yudkowsky poses the following canonical problem:

1% of women at age forty who participate in routine screening have breast cancer. 80% of women with breast cancer will get positive mammographies. 9.6% of women without breast cancer will also get positive mammographies.

A woman in this age group had a positive mammography in a routine screening. What is the probability that she actually has breast cancer?

The frightening thing is that only 15% of doctors get this right. And they’re off by a lot. That is, the average answer is in the range of 80% while the correct answer is 7.8%. Apparently, there is something about the way we think about the problem that makes 7.8% hard to accept, and Yudkowsky does a great job of walking you through the logic in painfully small steps.

Let’s try something similar here…

What Do We Know & What Does It Imply?
We have three pieces of information:

1% of sample are TRUE (that is, they have cancer)

80% of sample who are TRUE will test TRUE

9.6% of sample who are FALSE will test TRUE.

On the face of it, we should guess that the percentage of women who test TRUE who actually are TRUE (test positive and actually have cancer) is pretty small based on two facts provided: the actual percentage of women from the sample who are TRUE (regardless of testing) is only 1%, and the test has a false positive for 9.6% of those tested.

So, to solve this:

1) Assume we have a sample of 1000 women (I use 1000 to reduce the amount I have to talk about fractional people, but I don’t use 10,000 as I get lost in the zeros).

2) We know that the reality is that of the 1,000 women, 10 will have cancer (1%).

990 = no cancer
10 = cancer

3) Of the 10 who have cancer, 8 will test positive
8 out 1000 women tested will test True and are True

4) Of the 990 with no cancer 9.6% will also test positive = 990 * .096 = 95.04.
95.04 women out of 1,000 will test True but are False.

5) The total number testing true is 8 + 95.04 = 103.04.
Of these, 8 actually have Cancer.

6) So the value for tests positive (103.04) versus is positive (8) is 8/103.4 or 0.773 or 7.8%

Posted in Essentials | 3 Comments