Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Added F# WebAPI and Updated Projects Section of README
Browse files Browse the repository at this point in the history
  • Loading branch information
odytrice committed Oct 2, 2016
1 parent 136f6bc commit 37986f0
Show file tree
Hide file tree
Showing 13 changed files with 582 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -36,15 +36,19 @@ Also see [ASP NET Community Standup - June 21st, 2016 - Mads Visits](https://www
Full, template based projects available in generator:

- Empty Web Application
- Empty Web Application (F#)
- Console Application
- Console Application (F#)
- Web Application
- Web Application Basic [without Membership and Authorization]
- Web Application Basic [without Membership and Authorization] (F#)
- Web API Application
- Web API Application (F#)
- Nancy ASP.NET Application
- Class Library
- Class Library (F#)
- Unit Test project (xUnit.net)
- Unit Test project (xUnit.net) (F#)

The Empty Web Application, Console Application, Web Application, Web Application Basic (a.k.a. Web Application No Auth), Web API Application and Class Library are based on the templates introduced with Visual Studio 2015. They are available and maintained in the [ASP.NET Templates project](https://github.com/aspnet/Templates).

Expand Down Expand Up @@ -82,6 +86,7 @@ The valid project types are:
- `fsharp_emptyweb` for F# Empty Web Application
- `fsharp_console` for F# Console Application
- `fsharp_lib` for F# Class Library
- `fsharp_webapi` for F# Web API Application
- `fsharp_webbasic` for F# Web Application Basic
- `fsharp_test` for F# Unit Test project (xUnit.net)

Expand Down
23 changes: 23 additions & 0 deletions app/index.js
Expand Up @@ -36,6 +36,7 @@ var AspnetGenerator = yeoman.generators.Base.extend({
'classlibrary',
'unittest',
'fsharp_lib',
'fsharp_webapi',
'fsharp_console',
'fsharp_emptyweb',
'fsharp_webbasic',
Expand Down Expand Up @@ -86,6 +87,9 @@ var AspnetGenerator = yeoman.generators.Base.extend({
}, {
name: 'Web API Application',
value: 'webapi'
}, {
name: 'Web API Application (F#)',
value: 'fsharp_webapi'
}, {
name: 'Nancy ASP.NET Application',
value: 'nancy'
Expand Down Expand Up @@ -177,6 +181,9 @@ var AspnetGenerator = yeoman.generators.Base.extend({
case 'fsharp_console':
app = "ConsoleApplication";
break;
case 'fsharp_webapi':
app = "WebAPIApplication";
break;
case 'fsharp_emptyweb':
app = "EmptyWebApplication";
break;
Expand Down Expand Up @@ -389,6 +396,21 @@ var AspnetGenerator = yeoman.generators.Base.extend({
this.fs.copy(this.sourceRoot() + '/README.md', this.applicationName + '/README.md');
mkdirp.sync(this.applicationName + '/wwwroot');
break;

case 'fsharp_webapi':
this.sourceRoot(path.join(__dirname, '../templates/projects/' + this.type));
this.fs.copy(this.sourceRoot() + '/../../gitignore.txt', this.applicationName + '/.gitignore');
this.copy(this.sourceRoot() + '/appsettings.json', this.applicationName + '/appsettings.json');
this.fs.copyTpl(this.sourceRoot() + '/../../Dockerfile.txt', this.applicationName + '/Dockerfile', this.templatedata);
this.fs.copyTpl(this.sourceRoot() + '/Startup.fs', this.applicationName + '/Startup.fs', this.templatedata);
this.fs.copyTpl(this.sourceRoot() + '/Program.fs', this.applicationName + '/Program.fs', this.templatedata);
this.fs.copyTpl(this.sourceRoot() + '/project.json', this.applicationName + '/project.json', this.templatedata);
this.fs.copyTpl(this.templatePath('Properties/**/*'), this.applicationName + '/Properties', this.templatedata);
this.fs.copyTpl(this.sourceRoot() + '/Controllers.fs', this.applicationName + '/Controllers.fs', this.templatedata);
this.fs.copy(this.sourceRoot() + '/web.config', this.applicationName + '/web.config');
this.fs.copy(this.sourceRoot() + '/README.md', this.applicationName + '/README.md');
mkdirp.sync(this.applicationName + '/wwwroot');
break;

case 'fsharp_webbasic':
this.sourceRoot(path.join(__dirname, '../templates/projects/' + this.type));
Expand Down Expand Up @@ -471,6 +493,7 @@ var AspnetGenerator = yeoman.generators.Base.extend({
case 'webapi':
case 'webbasic':
case 'fsharp_console':
case 'fsharp_webapi':
case 'fsharp_webbasic':
case 'fsharp_emptyweb':
this.log(chalk.green(' dotnet run'));
Expand Down
234 changes: 234 additions & 0 deletions templates/projects/fsharp_webapi/.gitignore
@@ -0,0 +1,234 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/

# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

# DNX
project.lock.json
artifacts/

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding add-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config

# Microsoft Azure Build Output
csx/
*.build.csdef

# Microsoft Azure Emulator
ecf/
rcf/

# Microsoft Azure ApplicationInsights config file
ApplicationInsights.config

# Windows Store app package directory
AppPackages/
BundleArtifacts/

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

# GhostDoc plugin setting file
*.GhostDoc.xml

# Node.js Tools for Visual Studio
.ntvs_analysis.dat

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions

# Paket dependency manager
.paket/paket.exe

# FAKE - F# Make
.fake/
32 changes: 32 additions & 0 deletions templates/projects/fsharp_webapi/Controllers.fs
@@ -0,0 +1,32 @@
namespace <%= namespace %>.Controllers

open System
open System.Collections.Generic
open System.Linq
open System.Threading.Tasks
open Microsoft.AspNetCore.Mvc


[<Route("api/[controller]")>]
type ValuesController() =
inherit Controller()

// GET api/values
[<HttpGet>]
member this.Get() = [| "value1"; "value2" |]

// GET api/values/5
[<HttpGet("{id}")>]
member this.Get(id:int) = "value"

// POST api/values
[<HttpPost>]
member this.Post([<FromBody>]value:string) = ()

// PUT api/values/5
[<HttpPut("{id}")>]
member this.Put(id:int, [<FromBody>]value:string) = ()

// DELETE api/values/5
[<HttpDelete("{id}")>]
member this.Delete(id:int) = ()
13 changes: 13 additions & 0 deletions templates/projects/fsharp_webapi/Dockerfile
@@ -0,0 +1,13 @@
FROM microsoft/dotnet:latest

COPY . /app

WORKDIR /app

RUN ["dotnet", "restore"]

RUN ["dotnet", "build"]

EXPOSE 5000/tcp

CMD ["dotnet", "run", "--server.urls", "http://*:5000"]
26 changes: 26 additions & 0 deletions templates/projects/fsharp_webapi/Program.fs
@@ -0,0 +1,26 @@
// Learn more about F# at http://fsharp.org

open System
open System.IO
open Microsoft.Extensions.Configuration
open Microsoft.AspNetCore.Hosting
open <%= namespace %>

[<EntryPoint>]
let main argv =

let config = ConfigurationBuilder()
.AddCommandLine(argv)
.AddEnvironmentVariables("ASPNETCORE_")
.Build()

let host = WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build()
host.Run();

0 // return an integer exit code

0 comments on commit 37986f0

Please sign in to comment.