Intialize API project.

This commit is contained in:
Kevin Matsubara 2026-03-15 11:05:56 +01:00
parent 3b25f390c4
commit ef6adf0823
9 changed files with 202 additions and 1 deletions

53
.gitignore vendored Normal file
View File

@ -0,0 +1,53 @@
# Build results
bin/
obj/
out/
# .NET user-specific files
*.user
*.rsuser
*.suo
*.userosscache
*.sln.docstates
# Rider
.idea/
*.sln.iml
# VS Code
.vscode/
# Visual Studio
.vs/
# Logs
*.log
# OS files
.DS_Store
Thumbs.db
# ASP.NET secrets
secrets.json
# Publish output
publish/
# NuGet
*.nupkg
*.snupkg
.nuget/
packages/
# Test results
TestResults/
*.trx
# Coverage
coverage/
*.coverage
*.coveragexml
# Temporary files
*.tmp
*.temp

View File

@ -0,0 +1,38 @@
namespace MusicAPI.Controllers
open System
open System.Collections.Generic
open System.Linq
open System.Threading.Tasks
open Microsoft.AspNetCore.Mvc
open Microsoft.Extensions.Logging
open MusicAPI
[<ApiController>]
[<Route("[controller]")>]
type WeatherForecastController (logger : ILogger<WeatherForecastController>) =
inherit ControllerBase()
let summaries =
[|
"Freezing"
"Bracing"
"Chilly"
"Cool"
"Mild"
"Warm"
"Balmy"
"Hot"
"Sweltering"
"Scorching"
|]
[<HttpGet>]
member _.Get() =
let rng = System.Random()
[|
for index in 0..4 ->
{ Date = DateTime.Now.AddDays(float index)
TemperatureC = rng.Next(-20,55)
Summary = summaries.[rng.Next(summaries.Length)] }
|]

13
MusicAPI.fsproj Normal file
View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="WeatherForecast.fs" />
<Compile Include="Controllers/WeatherForecastController.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
</Project>

36
Program.fs Normal file
View File

@ -0,0 +1,36 @@
namespace MusicAPI
#nowarn "20"
open System
open System.Collections.Generic
open System.IO
open System.Linq
open System.Threading.Tasks
open Microsoft.AspNetCore
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.HttpsPolicy
open Microsoft.Extensions.Configuration
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.Logging
module Program =
let exitCode = 0
[<EntryPoint>]
let main args =
let builder = WebApplication.CreateBuilder(args)
builder.Services.AddControllers()
let app = builder.Build()
app.UseHttpsRedirection()
app.UseAuthorization()
app.MapControllers()
app.Run()
exitCode

View File

@ -0,0 +1,25 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "http://localhost:5006",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "https://localhost:7072;http://localhost:5006",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -1,3 +1,11 @@
# MusicAPI
F# music API for offline server.
## .NET commands
initialize project:
* `dotnet new webapi -lang F# -o MusicAPI`
run project locally:
* `dotnet run`
## Deployment

11
WeatherForecast.fs Normal file
View File

@ -0,0 +1,11 @@
namespace MusicAPI
open System
type WeatherForecast =
{ Date: DateTime
TemperatureC: int
Summary: string }
member this.TemperatureF =
32.0 + (float this.TemperatureC / 0.5556)

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

9
appsettings.json Normal file
View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}