Skip to content
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

Update first-web-api.md #34947

Merged
merged 1 commit into from
Mar 13, 2025
Merged

Update first-web-api.md #34947

merged 1 commit into from
Mar 13, 2025

Conversation

dominiqueplante
Copy link
Contributor

@dominiqueplante dominiqueplante commented Mar 11, 2025

For me, putting the id in the body was the only way to get past the check in the method:

if (id != todoDTO.Id)
{
            return BadRequest();
}

Tracking item added by wadepickett:

Fixes #34954


Internal previews

📄 File 🔗 Preview link
aspnetcore/tutorials/first-web-api.md Tutorial: Create a controller-based web API with ASP.NET Core

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
For me, putting the id in the body was the only way to get past the check in 
the method:

```
if (id != todoDTO.Id)
{
            return BadRequest();
}
```
@guardrex guardrex requested a review from wadepickett March 12, 2025 10:48
@wadepickett wadepickett self-assigned this Mar 12, 2025
@dominiqueplante
Copy link
Contributor Author

To clarify a bit more, when I was testing, todoDTO.Id is 0 unless it is set

@timdeschryver
Copy link
Contributor

Oops, this is something that I've missed when porting this to .NET 9.
The change is indeed required to make it a valid request
@wadepickett I'm pinging you because I just saw you assigned yourself to this issue.

Before: 400 bad request

image

After: 204 no content
image

@dominiqueplante
Copy link
Contributor Author

So it sounds like this is the correct fix :)

I just looked at the walkthrough for minimal APIs and saw the same issue there also, FYI ->

https://learn.microsoft.com/en-us/aspnet/core/tutorials/min-web-api?view=aspnetcore-9.0&tabs=visual-studio

@timdeschryver and @wadepickett, is there anything else I need to do?

@wadepickett
Copy link
Contributor

Thanks very much @dominiqueplante, looks right. Just give me a moment to test it for versions/vs/vs studio text...

@wadepickett
Copy link
Contributor

Perfect, thanks @dominiqueplante! Thanks @timdeschryver for checking as well!

@wadepickett wadepickett merged commit 999a579 into dotnet:main Mar 13, 2025
3 checks passed
@wadepickett
Copy link
Contributor

wadepickett commented Mar 13, 2025

I should have asked first @dominiqueplante, since you found the issue and the fix is similar, if you wanted the chance to fix the other tutorial (See #34956 ) as well go for it. Otherwise, I can make the fix right away.

@dominiqueplante
Copy link
Contributor Author

Hi @wadepickett, I'll make the similar change in the other page - thanks for giving me the opportunity to do it :)

@dominiqueplante dominiqueplante deleted the patch-2 branch March 13, 2025 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a controller-based web API: Fix missing ID in PUT request body
3 participants