Adding WithRequest that contains two inputs#50
Closed
matt-lethargic wants to merge 1 commit intoardalis:mainfrom
Closed
Adding WithRequest that contains two inputs#50matt-lethargic wants to merge 1 commit intoardalis:mainfrom
matt-lethargic wants to merge 1 commit intoardalis:mainfrom
Conversation
|
@ardalis This PR would be really useful to have included. EDIT : after further exploration there is no need for the PR. After exploring and fiddling around I realise that the Model Binding actually takes care of this anyway. All that is needed is to create your Model Class and decorate your properties with the attributes you need. i.e. public class NewArticleRequest
{
[FromRoute(Name = "author")] public string Author { get; set; }
[FromBody] public Article Article { get; set; }
}Then you can make use of it in your End Point as follows [Route("/article")]
public class Post : BaseAsyncEndpoint
.WithRequest<NewArticleRequest>
.WithoutResponse
{
[HttpPost("{author}")]
[SwaggerOperation(
Summary = "Submit a new article",
Description = "Enables the submission of new articles",
OperationId = "B349A6C4-1198-4B53-B9BE-85232E06F16E",
Tags = new[] {"Article"})
]
public override Task<ActionResult> HandleAsync([FromRoute] NewArticleRequest request,
CancellationToken cancellationToken = new CancellationToken())
{
//// your implementation
}
}The only snag/issue/bug I seem to run into seems to be related only to the [FromRoute] is that it doesn't seem to bind those specific properties unless you explicity set the in the |
Owner
|
See discussion on #42. |
Author
|
As above see #42 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds in the ability to specify two request parameters for an endpoint so that it is possible to have a route parameter and a body. The case I'm specifically talking about is where you need to
POST/PUT/PATCHto a url/parents/123/childrento create a child object.This addresses what is talked about in issue #42 I believe this is a very common pattern and will solve issues for many people.
And if nothing else would it not be nice to solve 42!!!!