Skip to content

Commit

Permalink
#371 Add HTTP API example application.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjstone committed Sep 29, 2020
1 parent 0bf5e89 commit a19c50c
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 10 deletions.
7 changes: 7 additions & 0 deletions RapidField.SolidInstruments.sln
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RapidField.SolidInstruments
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RapidField.SolidInstruments.Web.DotNetNative", "src\RapidField.SolidInstruments.Web.DotNetNative\RapidField.SolidInstruments.Web.DotNetNative.csproj", "{6A53C072-71C8-42F1-90D9-9AE64F2848B2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RapidField.SolidInstruments.Example.HttpApiClient", "example\RapidField.SolidInstruments.Example.HttpApiClient\RapidField.SolidInstruments.Example.HttpApiClient.csproj", "{46A9050C-F99A-4F93-B98B-B67A53A3FA0A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -674,6 +676,10 @@ Global
{6A53C072-71C8-42F1-90D9-9AE64F2848B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A53C072-71C8-42F1-90D9-9AE64F2848B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A53C072-71C8-42F1-90D9-9AE64F2848B2}.Release|Any CPU.Build.0 = Release|Any CPU
{46A9050C-F99A-4F93-B98B-B67A53A3FA0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46A9050C-F99A-4F93-B98B-B67A53A3FA0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46A9050C-F99A-4F93-B98B-B67A53A3FA0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46A9050C-F99A-4F93-B98B-B67A53A3FA0A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -756,6 +762,7 @@ Global
{3F1A6F2B-B84F-44C5-9E7D-5763C82CA926} = {F58E05BE-9DC6-41B4-8324-C006F6CE7CC7}
{20452BD4-3C2F-44EC-8DEB-14FD9FE8AA84} = {F58E05BE-9DC6-41B4-8324-C006F6CE7CC7}
{6A53C072-71C8-42F1-90D9-9AE64F2848B2} = {F58E05BE-9DC6-41B4-8324-C006F6CE7CC7}
{46A9050C-F99A-4F93-B98B-B67A53A3FA0A} = {BEB60D41-11BB-4C6E-8F5D-1E7990A27C34}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {834FCFB0-DA00-4ABD-9424-6FE1398A9F6E}
Expand Down
66 changes: 66 additions & 0 deletions cicd/modules/AutomationTools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ $ChoclateyPackageNameForDotNetCoreSdk = "dotnetcore-sdk";
$ChoclateyPackageNameForHub = "hub";
$ChoclateyPackageNameForLeanify = "leanify";
$ChoclateyPackageNameForNodeJs = "nodejs";
$ChoclateyPackageNameForNSwagStudio = "nswagstudio";
$ChoclateyPackageNameForOpenCover = "opencover.portable";
$ChoclateyPackageNameForOpenSsl = "openssl.light";
$ChoclateyPackageNameForPsake = "psake";
Expand Down Expand Up @@ -71,6 +72,7 @@ $SuppressHtmlMinifier = $false;
$SuppressHub = $true;
$SuppressLeanify = $true;
$SuppressNodeJs = $false;
$SuppressNSwagStudio = $false;
$SuppressNuGet = $false;
$SuppressOpenCover = $false;
$SuppressOpenSsl = $true;
Expand Down Expand Up @@ -155,6 +157,15 @@ Function GetNodeJsInstallationStatus
Return (GetChocolateyInstallationStatus) -and (choco list -lo | Where-Object { $_.ToLower().StartsWith("$ChoclateyPackageNameForNodeJs") });
}

<#
.Synopsis
Returns a boolean value indicating whether or not NSwagStudio is installed in the current environment.
#>
Function GetNSwagStudioInstallationStatus
{
Return (GetChocolateyInstallationStatus) -and (choco list -lo | Where-Object { $_.ToLower().StartsWith("$ChoclateyPackageNameForNSwagStudio") });
}

<#
.Synopsis
Returns a boolean value indicating whether or not NuGet is installed in the current environment.
Expand Down Expand Up @@ -232,6 +243,7 @@ Function InstallAllAutomationTools
InstallHtmlMinifier;
InstallHub;
InstallLeanify;
InstallNSwagStudio;
InstallOpenCover;
InstallOpenSsl;
InstallPoshGit;
Expand Down Expand Up @@ -424,6 +436,28 @@ Function InstallNodeJs
ComposeFinish "Finished installing Node.js.";
}

<#
.Synopsis
Installs NSwagStudio in the current environment.
#>
Function InstallNSwagStudio
{
If ($SuppressNSwagStudio -eq $true)
{
ComposeNormal "Suppressing installation of NSwagStudio.";
Return;
}
ElseIf (GetNSwagStudioInstallationStatus)
{
ComposeNormal "NSwagStudio is already installed.";
Return;
}

ComposeStart "Installing NSwagStudio.";
UseChocolateyToInstall -PackageName "$ChoclateyPackageNameForNSwagStudio";
ComposeFinish "Finished installing NSwagStudio.";
}

<#
.Synopsis
Installs NuGet in the current environment.
Expand Down Expand Up @@ -806,6 +840,18 @@ Function RestoreNodeJs
ComposeFinish "Finished restoring Node.js.";
}

<#
.Synopsis
Uninstalls, if necessary, and installs NSwagStudio in the current environment.
#>
Function RestoreNSwagStudio
{
ComposeStart "Restoring NSwagStudio.";
UninstallNSwagStudio;
InstallNSwagStudio;
ComposeFinish "Finished restoring NSwagStudio.";
}

<#
.Synopsis
Uninstalls, if necessary, and installs NuGet in the current environment.
Expand Down Expand Up @@ -903,6 +949,7 @@ Function UninstallAllAutomationTools
UninstallHtmlMinifier;
UninstallHub;
UninstallLeanify;
UninstallNSwagStudio;
UninstallOpenCover;
UninstallOpenSsl;
UninstallPoshGit;
Expand Down Expand Up @@ -1045,6 +1092,25 @@ Function UninstallNodeJs
}
}

<#
.Synopsis
Uninstalls NSwagStudio in the current environment.
#>
Function UninstallNSwagStudio
{
If ($SuppressNSwagStudio -eq $true)
{
ComposeNormal "Suppressing uninstallation of NSwagStudio.";
Return;
}
ElseIf (GetNSwagStudioInstallationStatus)
{
ComposeStart "Uninstalling NSwagStudio.";
UseChocolateyToUninstall -PackageName "$ChoclateyPackageNameForNSwagStudio";
ComposeFinish "Finished uninstalling NSwagStudio.";
}
}

<#
.Synopsis
Uninstalls NuGet in the current environment.
Expand Down
1 change: 1 addition & 0 deletions en-US_User.dic
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ noindex
nologo
norepair
npm
nswagstudio
nuget
nullable
Nwn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ public ApplicationDependencyPackage()
/// </returns>
protected override IEnumerable<IDependencyModule<ServiceCollection>> CreateModules(IConfiguration applicationConfiguration) => new IDependencyModule<ServiceCollection>[]
{
new ApplicationDependencyModule(applicationConfiguration),
new DatabaseContextDependencyModule(applicationConfiguration),
new ServiceBusDependencyModule(applicationConfiguration),
new MessageHandlerModule(applicationConfiguration)
new CommandHandlerModule(applicationConfiguration),
new EventHandlerModule(applicationConfiguration),
new MessageHandlerModule(applicationConfiguration),
new ApplicationDependencyModule(applicationConfiguration)
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
// Copyright (c) RapidField LLC. Licensed under the MIT License. See LICENSE.txt in the project root for license information.
// =================================================================================================================================

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RapidField.SolidInstruments.Command;
using RapidField.SolidInstruments.Core.ArgumentValidation;
using RapidField.SolidInstruments.Example.Domain.Commands.ModelState.User;
using RapidField.SolidInstruments.Example.Domain.Messages.Command.ModelState.User;
using RapidField.SolidInstruments.Example.Domain.Models.User;
using RapidField.SolidInstruments.Serialization;
using System;
using System.Diagnostics;
using System.Net;
using System.Text;

namespace RapidField.SolidInstruments.Example.Domain.AccessControl.HttpApi.Controllers
{
Expand Down Expand Up @@ -46,7 +49,12 @@ public UserController(ICommandMediator mediator)
/// A status code result.
/// </returns>
[HttpDelete]
public IActionResult Delete([FromRoute] Guid identifier)
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[Route("{identifier:Guid}")]
public ActionResult Delete([FromRoute] Guid identifier)
{
try
{
Expand Down Expand Up @@ -81,7 +89,12 @@ public IActionResult Delete([FromRoute] Guid identifier)
/// model exists.
/// </returns>
[HttpGet]
public IActionResult Get([FromQuery] Guid identifier)
[ProducesResponseType(typeof(DomainModel), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[Route("{identifier:Guid}")]
public ActionResult<DomainModel> Get([FromRoute] Guid identifier)
{
try
{
Expand All @@ -92,7 +105,9 @@ public IActionResult Get([FromQuery] Guid identifier)
return NotFound(identifier);
}

return new JsonResult(model);
var serializer = new JsonSerializer<DomainModel>();
var response = Encoding.UTF8.GetString(serializer.Serialize(model));
return Ok(response);
}
catch (ArgumentException exception)
{
Expand All @@ -114,7 +129,10 @@ public IActionResult Get([FromQuery] Guid identifier)
/// A status code result.
/// </returns>
[HttpPost]
public IActionResult Post([FromBody] DomainModel model)
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public ActionResult Post([FromBody] DomainModel model)
{
try
{
Expand All @@ -141,7 +159,10 @@ public IActionResult Post([FromBody] DomainModel model)
/// A status code result.
/// </returns>
[HttpPut]
public IActionResult Put([FromBody] DomainModel model)
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public ActionResult Put([FromBody] DomainModel model)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using RapidField.SolidInstruments.InversionOfControl.DotNetNative.Extensions;
using System;
using System.Diagnostics;
using System.IO;

namespace RapidField.SolidInstruments.Example.Domain.AccessControl.HttpApi
{
Expand All @@ -24,14 +27,17 @@ public static class Program
/// </param>
public static void Main(String[] args)
{
//using var webExecutor = new ApplicationWebExecutor(ApplicationName);
//webExecutor.Execute(args);
var applicationConfiguration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
var host = Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webHost =>
{
webHost.UseConfiguration(applicationConfiguration);
webHost.ConfigureServices(services =>
{
services.AddControllers();
services.AddDependencyPackage(new ApplicationDependencyPackage(), applicationConfiguration);
});
webHost.Configure(application =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
Copyright (c) RapidField LLC. Licensed under the MIT License. See LICENSE.txt in the project root for license information.
-->

[![Solid Instruments](../../SolidInstruments.Logo.Color.Transparent.500w.png)](../../README.md)
- - -

# RapidField.SolidInstruments.Example.HttpApiClient

This document describes the purpose of the [`RapidField.SolidInstruments.Example.HttpApiClient`]() project.

## Purpose

This project exposes a sample collection of HTTP API clients that utilize the **Solid Instruments** [web](../../src/RapidField.SolidInstruments.Web/README.md) constructs.

## License

[![License](https://img.shields.io/github/license/rapidfield/solid-instruments?style=flat&color=lightseagreen&label=license&logo=open-access&logoColor=lightgrey)](../../LICENSE.txt)

**Solid Instruments** is [MIT-licensed](https://en.wikipedia.org/wiki/MIT_License). Review the [license terms](../../LICENSE.txt) for more information.

<br />

- - -

<br />

[![RapidField](../../RapidField.Logo.Color.Black.Transparent.200w.png)](https://www.rapidfield.com)

###### Copyright (c) RapidField LLC. All rights reserved. "RapidField" and "Solid Instruments" are trademarks of RapidField LLC.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) RapidField LLC. Licensed under the MIT License. See LICENSE.txt in the project root for license information.
-->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Authors>Solid Instruments contributors</Authors>
<Company>RapidField</Company>
<Copyright>Copyright (c) RapidField LLC. All rights reserved.</Copyright>
<Product>Solid Instruments</Product>
<Description>This project exposes a sample collection of HTTP API clients that utilize the Solid Instruments web constructs.</Description>
<Version>$(BuildVersion)</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\netstandard2.1\RapidField.SolidInstruments.Example.HttpApiClient.xml</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard2.1\RapidField.SolidInstruments.Example.HttpApiClient.xml</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>
<ItemGroup>
<Content Include="..\..\LICENSE.txt" Link="LICENSE.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\RapidField.SolidInstruments.Core\RapidField.SolidInstruments.Core.csproj" />
<ProjectReference Include="..\..\src\RapidField.SolidInstruments.Web\RapidField.SolidInstruments.Web.csproj" />
</ItemGroup>
</Project>

0 comments on commit a19c50c

Please sign in to comment.