(()=>{
const authData = {
Login: 'admin',
Password: 'rnf23nfr0wenf'
}
const options = {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify(authData)
};
fetch('http://localhost:53187/api/values', options)
.then(response => response.text())
.then(data => console.warn(data));
})();
undefined
// result: 'admin_rnf23nfr0wenf'
namespace WebApiServer.Controllers
{
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Models;
[Route("api/[controller]")]
public class ValuesController : Controller
{
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] {"value1", "value2", "value3"};
}
// GET api/values/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/values
[HttpPost]
public string Post(/*[FromForm]*/ AuthModel Form)
{
return $"result: '{Form?.Login}__{Form?.Password}'";
}
// 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)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebApiServer.Models
{
public class AuthModel
{
public string Login { get; }
public string Password { get; }
}
}
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace WebApiServer
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace WebApiServer
{
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();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseDefaultFiles();
app.UseStaticFiles();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
}
А код, который следует после await попадает в Task queue, и как только промис отрезолвится, тогда и EventLoop отправит в CallStack этот самый код, который следует после await?