This section builds upon the quick start. If you haven’t completed the quick start yet, you can find it here or to the right.

Read: 5 minutes Code: 10 minutes

Add an OpenAPI Definition

Add a new file named kuno.json to configure the API and point the schema reference to http://cdn.kuno.io/schemas/application.json. Add a title, description and version. The resulting file should look something like the following:

{
  "kuno": {
    "title": "Hello World API",
    "version": "1.0.0",
    "description": "This is the Hello World API"
  }
}

Run the application and navigate to http://localhost:5000/swagger. You should see the additional information in the definition.

You can continue to update the Open API definition to add contact, terms of service, etc.

Add Comments and Metadata

You must first go the Project Properties and then find the Build tab. Make sure that the “XML documentation file” checkbox is checked. You can leave the default location.

Add summary comments to the HelloWorld class and value comments to the Name property of the HelloWorldRequest class. Also update the endpoint attribute to specify the method and add tags.

public class HelloWorldRequest
{
    /// <value>
    /// The name of the user that will be greeted.
    /// </value>
    public string Name { get; set; }
}

/// <summary>
/// Greets the user when name is supplied.
/// </summary>
[EndPoint("greet", Method = "GET", Tags = new [] { "Greetings" })]
public class HelloWorld : Function<HelloWorldRequest, string>
{
    public override string Receive(HelloWorldRequest instance)
    {
        return "Hello " + instance.Name + "!";
    }
}

Run the application and navigate to http://localhost:5000/swagger. You should see the comments that you have added on the endpoint and model.

Add Code Analysis

Install the Kuno.CodeAnalysis NuGet package. This will install the analyzer. In the Package Managaer Console run the following command:

Install-Package Kuno.CodeAnalysis

Notice that the HelloWorldRequest has an error. The information for the error can be found in the Error List window. Click the K1001 error and navigate to the rule page.

Fix the request so that it looks like the following.

public class HelloWorldRequest
{
    public string Name { get; }

    public HelloWorldRequest(string name)
    {
        this.Name = name;
    }
}

Deploy the API

The easiest way to deploy the API is directly in Visual Studio. First we will need to turn the console app into a web app so that we get the publishing features enabled. Right-click on the project in solution explorer and then click on “Edit HelloWorldService.csproj”. In the project file you will want to change the Sdk to Microsoft.NET.Sdk.Web.

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Kuno.Aspnetcore" Version="1.0.0" />
    <PackageReference Include="Kuno.CodeAnalysis" Version="1.0.0" />
  </ItemGroup>

  <ProjectExtensions><VisualStudio><UserProperties kuno_1json__JSONSchema="https://github.com/kuno-framework/kuno/raw/master/Kuno/schema.json" /></VisualStudio></ProjectExtensions>

</Project>

Do not change the version of Kuno that you are using.

You will notice that the project icon in Solution Explorer has changed to the web project icon. Look for a file named launchSettings.json under Properties. We need to re-configure the web to use our port and startup location. The updated file should look like the following.

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:5000",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "HelloWorldService": {
      "commandName": "Project"
    }
  }
}

Run the project which should now open the web. If the web looks fine, right-click on the project in solution explorer and then click “Publish”. Select “Microsoft Azure App Service” and “Create New” then click “Publish”. Make sure you are signed in then enter the information to create you new site. See the images below for an example. When finished filling this out, click “Create”. It will take a couple minutes to create the site and when finished the browser will open to your new site. Add /swagger to the end of the URL and test the site. You have successfuly deployed you API.

Browse Topics

More content can be found in the Learn More section. There you can find specifics on logging, data access, integration, best practices and more.