diff options
| author | mo khan <mo.khan@gmail.com> | 2019-10-19 20:56:41 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2019-10-19 20:56:41 -0600 |
| commit | 071d94fc5f212081dfafc9a2340c7822a7eed45b (patch) | |
| tree | a1a273da1b1df9851c0c1ab9a82df69472c201da /src | |
initial commit
Diffstat (limited to 'src')
| -rw-r--r-- | src/web.api/Controllers/WeatherForecastController.cs | 39 | ||||
| -rw-r--r-- | src/web.api/Program.cs | 26 | ||||
| -rw-r--r-- | src/web.api/Properties/launchSettings.json | 30 | ||||
| -rw-r--r-- | src/web.api/Startup.cs | 51 | ||||
| -rw-r--r-- | src/web.api/WeatherForecast.cs | 15 | ||||
| -rw-r--r-- | src/web.api/appsettings.Development.json | 9 | ||||
| -rw-r--r-- | src/web.api/appsettings.json | 10 | ||||
| -rw-r--r-- | src/web.api/web.api.csproj | 10 |
8 files changed, 190 insertions, 0 deletions
diff --git a/src/web.api/Controllers/WeatherForecastController.cs b/src/web.api/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..04f77bb --- /dev/null +++ b/src/web.api/Controllers/WeatherForecastController.cs @@ -0,0 +1,39 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Logging;
+
+namespace web.api.Controllers
+{
+ [ApiController]
+ [Route("[controller]")]
+ public class WeatherForecastController : ControllerBase
+ {
+ private static readonly string[] Summaries = new[]
+ {
+ "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
+ };
+
+ private readonly ILogger<WeatherForecastController> _logger;
+
+ public WeatherForecastController(ILogger<WeatherForecastController> logger)
+ {
+ _logger = logger;
+ }
+
+ [HttpGet]
+ public IEnumerable<WeatherForecast> Get()
+ {
+ var rng = new Random();
+ return Enumerable.Range(1, 5).Select(index => new WeatherForecast
+ {
+ Date = DateTime.Now.AddDays(index),
+ TemperatureC = rng.Next(-20, 55),
+ Summary = Summaries[rng.Next(Summaries.Length)]
+ })
+ .ToArray();
+ }
+ }
+}
diff --git a/src/web.api/Program.cs b/src/web.api/Program.cs new file mode 100644 index 0000000..7b70757 --- /dev/null +++ b/src/web.api/Program.cs @@ -0,0 +1,26 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+
+namespace web.api
+{
+ public class Program
+ {
+ public static void Main(string[] args)
+ {
+ CreateHostBuilder(args).Build().Run();
+ }
+
+ public static IHostBuilder CreateHostBuilder(string[] args) =>
+ Host.CreateDefaultBuilder(args)
+ .ConfigureWebHostDefaults(webBuilder =>
+ {
+ webBuilder.UseStartup<Startup>();
+ });
+ }
+}
diff --git a/src/web.api/Properties/launchSettings.json b/src/web.api/Properties/launchSettings.json new file mode 100644 index 0000000..799f513 --- /dev/null +++ b/src/web.api/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{
+ "$schema": "http://json.schemastore.org/launchsettings.json",
+ "iisSettings": {
+ "windowsAuthentication": false,
+ "anonymousAuthentication": true,
+ "iisExpress": {
+ "applicationUrl": "http://localhost:24975",
+ "sslPort": 44357
+ }
+ },
+ "profiles": {
+ "IIS Express": {
+ "commandName": "IISExpress",
+ "launchBrowser": true,
+ "launchUrl": "weatherforecast",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ },
+ "web.api": {
+ "commandName": "Project",
+ "launchBrowser": true,
+ "launchUrl": "weatherforecast",
+ "applicationUrl": "https://localhost:5001;http://localhost:5000",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ }
+ }
+}
diff --git a/src/web.api/Startup.cs b/src/web.api/Startup.cs new file mode 100644 index 0000000..97f8e8b --- /dev/null +++ b/src/web.api/Startup.cs @@ -0,0 +1,51 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.HttpsPolicy;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+
+namespace web.api
+{
+ public class Startup
+ {
+ public Startup(IConfiguration configuration)
+ {
+ Configuration = configuration;
+ }
+
+ public IConfiguration Configuration { get; }
+
+ // This method gets called by the runtime. Use this method to add services to the container.
+ public void ConfigureServices(IServiceCollection services)
+ {
+ services.AddControllers();
+ }
+
+ // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
+ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+ {
+ if (env.IsDevelopment())
+ {
+ app.UseDeveloperExceptionPage();
+ }
+
+ app.UseHttpsRedirection();
+
+ app.UseRouting();
+
+ app.UseAuthorization();
+
+ app.UseEndpoints(endpoints =>
+ {
+ endpoints.MapControllers();
+ });
+ }
+ }
+}
diff --git a/src/web.api/WeatherForecast.cs b/src/web.api/WeatherForecast.cs new file mode 100644 index 0000000..b303096 --- /dev/null +++ b/src/web.api/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System;
+
+namespace web.api
+{
+ public class WeatherForecast
+ {
+ public DateTime Date { get; set; }
+
+ public int TemperatureC { get; set; }
+
+ public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
+
+ public string Summary { get; set; }
+ }
+}
diff --git a/src/web.api/appsettings.Development.json b/src/web.api/appsettings.Development.json new file mode 100644 index 0000000..a2880cb --- /dev/null +++ b/src/web.api/appsettings.Development.json @@ -0,0 +1,9 @@ +{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Debug",
+ "System": "Information",
+ "Microsoft": "Information"
+ }
+ }
+}
diff --git a/src/web.api/appsettings.json b/src/web.api/appsettings.json new file mode 100644 index 0000000..81ff877 --- /dev/null +++ b/src/web.api/appsettings.json @@ -0,0 +1,10 @@ +{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft": "Warning",
+ "Microsoft.Hosting.Lifetime": "Information"
+ }
+ },
+ "AllowedHosts": "*"
+}
diff --git a/src/web.api/web.api.csproj b/src/web.api/web.api.csproj new file mode 100644 index 0000000..2209443 --- /dev/null +++ b/src/web.api/web.api.csproj @@ -0,0 +1,10 @@ +<Project Sdk="Microsoft.NET.Sdk.Web">
+
+ <PropertyGroup>
+ <TargetFramework>netcoreapp3.0</TargetFramework>
+ </PropertyGroup>
+
+ <ItemGroup>
+ </ItemGroup>
+
+</Project>
|
