Comments (8)
Answer 2:
Doesn't this section of readme addresses this exact question?
https://github.com/ardalis/ApiEndpoints#how-can-i-bind-parameters-from-multiple-locations-to-my-model
from apiendpoints.
Try
[HttpPut("/investment-types/{Id}")]
public override async Task<ActionResult<InvestmentTypePutResponse>> HandleAsync(Guid id, InvestmentTypePutRequest request, CancellationToken cancellationToken = default) {}
public class InvestmentTypePutRequest
{
public byte[] Version { get; set; } = null!;
public string Name { get; set; } = null!;
public string? Description { get; set; }
}
Edit: Oh, right, that cannot be done since HandleAsync
signature is fixed..
from apiendpoints.
Okay, let's think about it in a different way.
Why does Handle
method needs to be predefined at all? We can just do this:
public class Put : BaseEndpointAsync
{
[HttpPut("/investment-types/{Id:Guid}")]
public async Task<ActionResult<InvestmentTypePutResponse>> HandleAsync(Guid id, InvestmentTypePutRequest request)
{
}
}
public class InvestmentTypePutRequest
{
public byte[] Version { get; set; } = null!;
public string Name { get; set; } = null!;
public string? Description { get; set; }
}
And analyzer will keep us from defining multiple actions.
Side note:
- I think it's ok to define all actions this way. No
WithRequest/WithResponce
needed. MediatR needs them to resolve information about the command/query so it can be called from some other code, but in this case Asp.Net will resolve all information, and direct invocations to our action automatically. - So essentially, this package can be boiled down to
- Base class
BaseEndpoint
- Analyzer (that's keeps developers from creating more than one action in a controller)
- And maybe source generator (that will automatically add
[Route]
attribute to every controller based on it's folder or some other criteria). Everything else (file nesting and request handling) is already built-in. maxkoshevoi@41e49ee
- Base class
from apiendpoints.
Original question seemed to indicate that wasn't working for him, but admittedly I don't have a reproduction of the problem, yet.
from apiendpoints.
Original question seemed to indicate that wasn't working for him
Maybe it's because [FromRoute]
is missing from parameter's signature?
I haven't tried to reproduce it either, but I can say for sure that inheriting directly from BaseEndpointAsync
would work.
from apiendpoints.
This issue was created by Steve for me. I've created a VS solution with a repro at https://github.com/msantor/ApiEnpointsIssue124. I've included a Postman collection with the test call I'm using. It's possible I'm missing something very simple. Thank you for your time.
from apiendpoints.
I resolved my problem. It was because I had multiple [FromBody] attributes directly on the request type. I created an additional class to represent the body of the request and model binding does the rest. Sorry to have wasted everyone's time on this. I needed to more thoroughly read through the documentation. Please close this issue.
from apiendpoints.
Ah, yes. That will do it. We've all been there. :)
from apiendpoints.
Related Issues (20)
- Cant read the request body using StreamReader HOT 5
- Swagger documentation in separate class HOT 2
- add consumes/ produces attribute
- Update docs with vs code tip per this exchange
- Docs : Add support to filters by module
- Transitive dependency `Microsoft.NETCore.Platforms.3.1.4` contains vulnerabilities according
- Using `.` in Swagger OperationIds makes swagger client generators fail HOT 2
- Update GitHub project to set project website to https://apiendpoints.ardalis.com HOT 2
- 2 Values from Route failed HOT 2
- Visual Studio 2022 Endpoint Explorer Integration HOT 15
- Unable to control OpenAPI operation ID with ApiExplorerSettings
- Allow for multiple parameters on an endpoint HOT 1
- Example on how to tackle Duplicate Code in Endpoints HOT 1
- Minimal Apis HOT 1
- Update Getting Started section HOT 1
- how to support OData queries and APIVersion? HOT 1
- Get Payload in body as well as the uploaded File
- .NET 8.0 & Libraries
- Add sample / improve docs when starting with an empty web api project HOT 2
- Ability to have RequestBody object, but also Request Query. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apiendpoints.