-
Notifications
You must be signed in to change notification settings - Fork 10.4k
MapAction MVP #29878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MapAction MVP #29878
Changes from all commits
f395842
b0dd7b1
1f2884e
d2a2177
cbec2d1
4865f2f
bf7a263
3eb9027
629f09f
e05c4c9
284d1a1
dac8375
c6bc2cf
d055ba4
e167639
dae72ad
15f2e6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.AspNetCore.Http | ||
{ | ||
/// <summary> | ||
/// Defines a contract that represents the result of an HTTP endpoint. | ||
/// </summary> | ||
public interface IResult | ||
{ | ||
/// <summary> | ||
/// Write an HTTP response reflecting the result. | ||
/// </summary> | ||
/// <param name="httpContext">The <see cref="HttpContext"/> for the current request.</param> | ||
/// <returns>A task that represents the asynchronous execute operation.</returns> | ||
Task ExecuteAsync(HttpContext httpContext); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNetCore.Http.Metadata | ||
{ | ||
/// <summary> | ||
/// Interface marking attributes that specify a parameter should be bound using the request body. | ||
/// </summary> | ||
public interface IFromBodyMetadata | ||
{ | ||
/// <summary> | ||
/// Gets whether empty input should be rejected or treated as valid. | ||
/// </summary> | ||
bool AllowEmpty => false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNetCore.Http.Metadata | ||
{ | ||
/// <summary> | ||
/// Interface marking attributes that specify a parameter should be bound using form-data in the request body. | ||
/// </summary> | ||
public interface IFromFormMetadata | ||
{ | ||
/// <summary> | ||
/// The form field name. | ||
/// </summary> | ||
string? Name { get; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNetCore.Http.Metadata | ||
{ | ||
/// <summary> | ||
/// Interface marking attributes that specify a parameter should be bound using the request headers. | ||
/// </summary> | ||
public interface IFromHeaderMetadata | ||
{ | ||
/// <summary> | ||
/// The request header name. | ||
/// </summary> | ||
string? Name { get; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNetCore.Http.Metadata | ||
{ | ||
/// <summary> | ||
/// Interface marking attributes that specify a parameter should be bound using the request query string. | ||
/// </summary> | ||
public interface IFromQueryMetadata | ||
{ | ||
/// <summary> | ||
/// The name of the query string field. | ||
/// </summary> | ||
string? Name { get; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNetCore.Http.Metadata | ||
{ | ||
/// <summary> | ||
/// Interface marking attributes that specify a parameter should be bound using route-data from the current request. | ||
/// </summary> | ||
public interface IFromRouteMetadata | ||
{ | ||
/// <summary> | ||
/// The <see cref="HttpRequest.RouteValues"/> name. | ||
/// </summary> | ||
string? Name { get; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNetCore.Http.Metadata | ||
{ | ||
/// <summary> | ||
/// Interface marking attributes that specify a parameter should be bound using request services. | ||
/// </summary> | ||
public interface IFromServiceMetadata | ||
{ | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,54 @@ | ||
{ | ||
{ | ||
"solution": { | ||
"path": "..\\..\\AspNetCore.sln", | ||
"projects" : [ | ||
"projects": [ | ||
"src\\Hosting\\Abstractions\\src\\Microsoft.AspNetCore.Hosting.Abstractions.csproj", | ||
"src\\Hosting\\Hosting\\src\\Microsoft.AspNetCore.Hosting.csproj", | ||
"src\\Hosting\\Server.Abstractions\\src\\Microsoft.AspNetCore.Hosting.Server.Abstractions.csproj", | ||
"src\\Hosting\\TestHost\\src\\Microsoft.AspNetCore.TestHost.csproj", | ||
"src\\Http\\Authentication.Abstractions\\src\\Microsoft.AspNetCore.Authentication.Abstractions.csproj", | ||
"src\\Http\\Authentication.Core\\src\\Microsoft.AspNetCore.Authentication.Core.csproj", | ||
"src\\Http\\Authentication.Core\\test\\Microsoft.AspNetCore.Authentication.Core.Test.csproj", | ||
"src\\Http\\Headers\\src\\Microsoft.Net.Http.Headers.csproj", | ||
"src\\Http\\Headers\\test\\Microsoft.Net.Http.Headers.Tests.csproj", | ||
"src\\Http\\Http\\src\\Microsoft.AspNetCore.Http.csproj", | ||
"src\\Http\\Http\\test\\Microsoft.AspNetCore.Http.Tests.csproj", | ||
"src\\Http\\Http.Abstractions\\src\\Microsoft.AspNetCore.Http.Abstractions.csproj", | ||
"src\\Http\\Http.Abstractions\\test\\Microsoft.AspNetCore.Http.Abstractions.Tests.csproj", | ||
"src\\Http\\Http.Extensions\\src\\Microsoft.AspNetCore.Http.Extensions.csproj", | ||
"src\\Http\\Http.Extensions\\test\\Microsoft.AspNetCore.Http.Extensions.Tests.csproj", | ||
"src\\Http\\Http.Features\\src\\Microsoft.AspNetCore.Http.Features.csproj", | ||
"src\\Http\\Http.Features\\test\\Microsoft.AspNetCore.Http.Features.Tests.csproj", | ||
"src\\Http\\Http\\perf\\Microsoft.AspNetCore.Http.Performance.csproj", | ||
"src\\Http\\Http\\src\\Microsoft.AspNetCore.Http.csproj", | ||
"src\\Http\\Http\\test\\Microsoft.AspNetCore.Http.Tests.csproj", | ||
"src\\Http\\Metadata\\src\\Microsoft.AspNetCore.Metadata.csproj", | ||
"src\\Http\\Owin\\src\\Microsoft.AspNetCore.Owin.csproj", | ||
"src\\Http\\Owin\\test\\Microsoft.AspNetCore.Owin.Tests.csproj", | ||
"src\\Http\\samples\\SampleApp\\HttpAbstractions.SampleApp.csproj", | ||
"src\\Http\\WebUtilities\\src\\Microsoft.AspNetCore.WebUtilities.csproj", | ||
"src\\Http\\WebUtilities\\test\\Microsoft.AspNetCore.WebUtilities.Tests.csproj", | ||
"src\\Http\\Http\\perf\\Microsoft.AspNetCore.Http.Performance.csproj", | ||
"src\\Http\\Routing.Abstractions\\src\\Microsoft.AspNetCore.Routing.Abstractions.csproj", | ||
"src\\Http\\Routing.Abstractions\\test\\Microsoft.AspNetCore.Mvc.Routing.Abstractions.Tests.csproj", | ||
"src\\Http\\Routing\\perf\\Microsoft.AspNetCore.Routing.Performance.csproj", | ||
"src\\Http\\Routing\\samples\\MapActionSample\\MapActionSample.csproj", | ||
"src\\Http\\Routing\\src\\Microsoft.AspNetCore.Routing.csproj", | ||
"src\\Http\\Routing\\test\\FunctionalTests\\Microsoft.AspNetCore.Routing.FunctionalTests.csproj", | ||
"src\\Http\\Routing\\test\\UnitTests\\Microsoft.AspNetCore.Routing.Tests.csproj", | ||
"src\\Http\\Routing.Abstractions\\src\\Microsoft.AspNetCore.Routing.Abstractions.csproj", | ||
"src\\Http\\Routing.Abstractions\\test\\Microsoft.AspNetCore.Mvc.Routing.Abstractions.Tests.csproj", | ||
"src\\Hosting\\TestHost\\src\\Microsoft.AspNetCore.TestHost.csproj", | ||
"src\\Http\\Routing\\test\\testassets\\RoutingWebSite\\RoutingWebSite.csproj", | ||
"src\\Http\\Routing\\test\\testassets\\RoutingSandbox\\RoutingSandbox.csproj", | ||
"src\\Http\\Routing\\test\\testassets\\Benchmarks\\Benchmarks.csproj", | ||
"src\\Servers\\Kestrel\\Kestrel\\src\\Microsoft.AspNetCore.Server.Kestrel.csproj", | ||
"src\\Middleware\\StaticFiles\\src\\Microsoft.AspNetCore.StaticFiles.csproj", | ||
"src\\Servers\\Kestrel\\Core\\src\\Microsoft.AspNetCore.Server.Kestrel.Core.csproj", | ||
"src\\Hosting\\Hosting\\src\\Microsoft.AspNetCore.Hosting.csproj", | ||
"src\\Servers\\Connections.Abstractions\\src\\Microsoft.AspNetCore.Connections.Abstractions.csproj", | ||
"src\\Hosting\\Abstractions\\src\\Microsoft.AspNetCore.Hosting.Abstractions.csproj", | ||
"src\\Hosting\\Server.Abstractions\\src\\Microsoft.AspNetCore.Hosting.Server.Abstractions.csproj", | ||
"src\\Servers\\Kestrel\\Transport.Sockets\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj", | ||
"src\\Middleware\\HttpOverrides\\src\\Microsoft.AspNetCore.HttpOverrides.csproj", | ||
"src\\Servers\\IIS\\IISIntegration\\src\\Microsoft.AspNetCore.Server.IISIntegration.csproj", | ||
"src\\Http\\Routing\\test\\testassets\\RoutingSandbox\\RoutingSandbox.csproj", | ||
"src\\Http\\Routing\\test\\testassets\\RoutingWebSite\\RoutingWebSite.csproj", | ||
"src\\Http\\WebUtilities\\perf\\Microsoft.AspNetCore.WebUtilities.Performance\\Microsoft.AspNetCore.WebUtilities.Performance.csproj", | ||
"src\\Security\\Authorization\\Policy\\src\\Microsoft.AspNetCore.Authorization.Policy.csproj", | ||
"src\\Http\\WebUtilities\\src\\Microsoft.AspNetCore.WebUtilities.csproj", | ||
"src\\Http\\WebUtilities\\test\\Microsoft.AspNetCore.WebUtilities.Tests.csproj", | ||
"src\\Http\\samples\\SampleApp\\HttpAbstractions.SampleApp.csproj", | ||
"src\\Middleware\\CORS\\src\\Microsoft.AspNetCore.Cors.csproj", | ||
"src\\Http\\Metadata\\src\\Microsoft.AspNetCore.Metadata.csproj", | ||
"src\\Middleware\\HttpOverrides\\src\\Microsoft.AspNetCore.HttpOverrides.csproj", | ||
"src\\Middleware\\StaticFiles\\src\\Microsoft.AspNetCore.StaticFiles.csproj", | ||
"src\\ObjectPool\\src\\Microsoft.Extensions.ObjectPool.csproj", | ||
"src\\WebEncoders\\src\\Microsoft.Extensions.WebEncoders.csproj", | ||
"src\\Testing\\src\\Microsoft.AspNetCore.Testing.csproj" | ||
"src\\Security\\Authorization\\Policy\\src\\Microsoft.AspNetCore.Authorization.Policy.csproj", | ||
"src\\Servers\\Connections.Abstractions\\src\\Microsoft.AspNetCore.Connections.Abstractions.csproj", | ||
"src\\Servers\\IIS\\IISIntegration\\src\\Microsoft.AspNetCore.Server.IISIntegration.csproj", | ||
"src\\Servers\\Kestrel\\Core\\src\\Microsoft.AspNetCore.Server.Kestrel.Core.csproj", | ||
"src\\Servers\\Kestrel\\Kestrel\\src\\Microsoft.AspNetCore.Server.Kestrel.csproj", | ||
"src\\Servers\\Kestrel\\Transport.Sockets\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj", | ||
"src\\Testing\\src\\Microsoft.AspNetCore.Testing.csproj", | ||
"src\\WebEncoders\\src\\Microsoft.Extensions.WebEncoders.csproj" | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="Microsoft.AspNetCore" /> | ||
<Reference Include="Microsoft.AspNetCore.Diagnostics" /> | ||
<Reference Include="Microsoft.AspNetCore.Hosting" /> | ||
<!-- Mvc.Core is referenced only for its attributes --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these attributes going to be replaced with new ones? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. We've been trying to avoid duplicating attributes as that can lead to confusion. |
||
<Reference Include="Microsoft.AspNetCore.Mvc.Core" /> | ||
<Reference Include="Microsoft.AspNetCore.Server.Kestrel" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 HttpApiSampleApp | ||
{ | ||
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>(); | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"profiles": { | ||
"HttpApiSampleApp": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": "true", | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:5001;http://localhost:5000", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace HttpApiSampleApp | ||
{ | ||
public class Startup | ||
{ | ||
// This method gets called by the runtime. Use this method to add services to the container. | ||
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
} | ||
|
||
// 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.UseRouting(); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
[HttpPost("/EchoTodo")] | ||
JsonResult EchoTodo([FromBody] Todo todo) => new(todo); | ||
|
||
endpoints.MapAction((Func<Todo, JsonResult>)EchoTodo); | ||
Tratcher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
endpoints.MapPost("/EchoTodoProto", async httpContext => | ||
{ | ||
var todo = await httpContext.Request.ReadFromJsonAsync<Todo>(); | ||
await httpContext.Response.WriteAsJsonAsync(todo); | ||
}); | ||
|
||
endpoints.MapGet("/", async context => | ||
{ | ||
await context.Response.WriteAsync("Hello World!"); | ||
}); | ||
}); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace HttpApiSampleApp | ||
{ | ||
public class Todo | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
public bool IsComplete { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.