# Update API with HTTP PUT - C# on Linux Episode 18

## Метаданные

- **Канал:** IAmTimCorey
- **YouTube:** https://www.youtube.com/watch?v=hSRI_JKiH5M
- **Дата:** 20.05.2026
- **Длительность:** 9:10
- **Просмотры:** 576
- **Источник:** https://ekstraktznaniy.ru/video/51641

## Описание

We are going to add an HTTP PUT command to update data into SQL in our Minimal API project. 

Full Training Courses: https://IAmTimCorey.com
Source Code: https://www.iamtimcorey.com/downloads/?code=linux-ep-18

## Транскрипт

### Segment 1 (00:00 - 05:00) []

Now's time to work on our update command where we'll use the HTTP verb put to update a record in the database. This video is part of a series dedicated to developing C# applications on Linux. Along the way, we're getting a better understanding of how Linux works and how to make our apps truly cross-platform. If you haven't already, subscribe to this channel to stay informed of new episodes as they come out. You'll also hear about new courses as I release them on YouTube as well as my paid content as well. My paid content on IAmTimCorey. com is what funds this free content. So, if you need more in-depth training on. NET, on SQL, on AI or APIs or anything else, I'd encourage you go there to help out this channel. All right, let's jump over to Linux and start working on our put command. So, let's open up our API service, go to our program. By the way, again, if you want the source code for any of this, you can get the link down the description for that source code. Okay. So, we have our um our post. Now, let's come down here and say and we'll say /api/tickets and [snorts] we're going to say async and we'll say task results and then no content and validation problem just like before. And then we'll say SQL data access SQL. And we don't yet have an update record, but we'll get that a minute. So, that gets us the start of our setup, but we're not quite done yet. Um what we need is we need our um We need our update record. So, let's come down here and let's open up our database proj- up our database project our SQL Server project. There we go. Make sure the database is running ticket DB go down to programmability stored procedures we have our update. And then the parameters for that are a little different. So, we have our ID our ticket title description date completed and priority. So, let's modify let's copy this record and modify it to fit we'll call this the update record. And we need to add a um — [clears throat] — a required And I could put a range on this. Um let's do it for you know range one and int. max value. That's the range for our ID. Um that we're not passing in negative value or something else like that. Okay. And we have our ticket description, but we also have our date completed. So, let's say date time nullable date completed. And no validation on that because it's a date time, but it's nullable meaning we don't necessarily um expect you're going to pass in that date time if um — [clears throat] — if you haven't modify or if you don't complete the record. Okay. So, now we have our um our record updated. Our update record, actually. Um we can save this and then we can come up here and pass this in as well. Ticket update record and we'll call it ticket. Like so. And let's put this on the new line like before because this is again very, very long. And this right here is saying not all code paths return a value, which is true. So, we need to fix that before we're done. Okay. So, await SQL save data async and we're going to say dbo. sp_tickets _update pass in the ticket DB, which is our connection string name. And then return typed results

### Segment 2 (05:00 - 09:00) [5:00]

. no content. And again, there are other things um that you can do for return types that like you can return no content, uh but you can also return the um the new record has it been updated if you want to. There's lots of different things you can do. We're not going to get into that for this course. It's we're keeping it really simple. Um but this is our update. So, that's it. Again, Dapper makes it so simple, especially with the wrapper we wrote. Um stored procedure name uh the connection string name and the model. Done. Okay. So, with that we can come down here to our run. We can say start debug. Wait for it to launch. It's going to take a second or two, especially on this machine. Come on. Here we go. So, we're running. We got that nice Go with Swagger now, which is awesome. We have a put command now. Again, I covered this in the last video, but a put command is where you're updating the entire record. Or could be The patch command is where you're patching a record, meaning you might be updating a um a an item or two, right? You might be updating just the title or just the date completed. Which, if I was doing this for real, I'd probably have a patch command that was just complete the ticket. You wouldn't even pass anything in it except the ID of the ticket. And then it would um update that ticket to say completed. And you may change the priority to be another patch command you can do. But, in our case, let's hit try it out. And actually, first, I'm going to load the tickets because I don't remember which ticket was which. Um let's try it out. Execute. So, we have 107, 109, and 110. 109 is a whole mess. It's got no title, no description, and no priority. Let's change that. So, 109 is the ID. Normally, in our front-end application, we'll have loaded this information from a database. So, you already have the data pre-filled, and we just modify it. But, in our case, for our API, you have to manually do it. So, 1009. Uh I said 109, but it's 1009. Um the title is this is our sam or let's call it sample record. And then the description will be this is our sample record. And the priority should be five because this is not a high priority. Let's execute. And when we do, we get back a 204 meaning that no content came back, but we should be good. Um so let's execute this again. Look at 1009. It's a sample record. There's our sample record and priority of five. Cool. So our update is working and if we were to um change something here, let's say we don't pass in uh ticket title is required. So let's knock that off and hit execute. When we do, we get a 400 message saying that ticket title field is required. So we're all set. We're good to go. Um that's all there is to updating our record. Okay? So super simple once we have once we're kind of in the groove here of how we do things is we just say, "Hey, do the same thing only it's a put command and here's the information pass it in and there you go. " So next up what we'll do is work on the delete command. But until then, thanks for watching and as always, I am Tim Corey. —
