From 92e8bb7523c775014ccf68355e3f0178ebf4a61c Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Wed, 26 Sep 2018 19:18:41 +0200 Subject: implemented fudamental Web Api --- DSACore/Controllers/CommandsController.cs | 49 +++++++++++++++++++++++++++++++ DSACore/Controllers/ValuesController.cs | 45 ++++++++++++++++++++++++++++ DSACore/DSACore.csproj | 15 ++++++++++ DSACore/Models/Command.cs | 13 ++++++++ DSACore/Program.cs | 24 +++++++++++++++ DSACore/Properties/launchSettings.json | 30 +++++++++++++++++++ DSACore/Startup.cs | 47 +++++++++++++++++++++++++++++ DSACore/appsettings.Development.json | 9 ++++++ DSACore/appsettings.json | 8 +++++ 9 files changed, 240 insertions(+) create mode 100644 DSACore/Controllers/CommandsController.cs create mode 100644 DSACore/Controllers/ValuesController.cs create mode 100644 DSACore/DSACore.csproj create mode 100644 DSACore/Models/Command.cs create mode 100644 DSACore/Program.cs create mode 100644 DSACore/Properties/launchSettings.json create mode 100644 DSACore/Startup.cs create mode 100644 DSACore/appsettings.Development.json create mode 100644 DSACore/appsettings.json (limited to 'DSACore') diff --git a/DSACore/Controllers/CommandsController.cs b/DSACore/Controllers/CommandsController.cs new file mode 100644 index 0000000..bda8fd0 --- /dev/null +++ b/DSACore/Controllers/CommandsController.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using DSACore.Models; +using Microsoft.AspNetCore.Mvc; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace DSACore.Controllers +{ + [Route("api/[controller]")] + public class CommandsController : Controller + { + // GET: api/ + [HttpGet] + public IEnumerable Get() + { + return new string[] { "value1", "value2" }; + } + + // GET api//5 + [HttpGet("{id}")] + public string Get(int id) + { + return "value"; + } + + // POST api//Felis + [HttpPost] + public string Post([FromBody]Command cmd) + { + return cmd.Name + " strichelt erfolgreich das Einhorn" + cmd.CmdText; + } + + + // PUT api//5 + [HttpPut("{id}")] + public void Put(int id, [FromBody]string value) + { + } + + // DELETE api//5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} diff --git a/DSACore/Controllers/ValuesController.cs b/DSACore/Controllers/ValuesController.cs new file mode 100644 index 0000000..eb08898 --- /dev/null +++ b/DSACore/Controllers/ValuesController.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +namespace DSACore.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ValuesController : ControllerBase + { + // GET api/values + [HttpGet] + public ActionResult> Get() + { + return new string[] { "value1", "value2" }; + } + + // GET api/values/5 + [HttpGet("{id}")] + public ActionResult Get(int id) + { + return "value"; + } + + // POST api/values + [HttpPost] + public void Post([FromBody] string value) + { + } + + // PUT api/values/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + // DELETE api/values/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} diff --git a/DSACore/DSACore.csproj b/DSACore/DSACore.csproj new file mode 100644 index 0000000..1661770 --- /dev/null +++ b/DSACore/DSACore.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp2.1 + + + + + + + + + + + diff --git a/DSACore/Models/Command.cs b/DSACore/Models/Command.cs new file mode 100644 index 0000000..75e3bee --- /dev/null +++ b/DSACore/Models/Command.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace DSACore.Models +{ + public class Command + { + public string Name { get; set; } + public string CmdText { get; set; } + } +} diff --git a/DSACore/Program.cs b/DSACore/Program.cs new file mode 100644 index 0000000..373a39e --- /dev/null +++ b/DSACore/Program.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace DSACore +{ + public class Program + { + public static void Main(string[] args) + { + CreateWebHostBuilder(args).Build().Run(); + } + + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); + } +} diff --git a/DSACore/Properties/launchSettings.json b/DSACore/Properties/launchSettings.json new file mode 100644 index 0000000..889d022 --- /dev/null +++ b/DSACore/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:29492", + "sslPort": 44365 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "api/commands", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "DSACore": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/commands", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/DSACore/Startup.cs b/DSACore/Startup.cs new file mode 100644 index 0000000..2d0c2a3 --- /dev/null +++ b/DSACore/Startup.cs @@ -0,0 +1,47 @@ +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.Logging; +using Microsoft.Extensions.Options; + +namespace DSACore +{ + 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.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + app.UseHsts(); + } + + app.UseHttpsRedirection(); + app.UseMvc(); + } + } +} diff --git a/DSACore/appsettings.Development.json b/DSACore/appsettings.Development.json new file mode 100644 index 0000000..e203e94 --- /dev/null +++ b/DSACore/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/DSACore/appsettings.json b/DSACore/appsettings.json new file mode 100644 index 0000000..def9159 --- /dev/null +++ b/DSACore/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +} -- cgit v1.3.1