From the course: Transitioning from Java to Kotlin
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Adding new products
From the course: Transitioning from Java to Kotlin
Adding new products
- [Instructor] We can now pull items from a SQL database. How would we allow for the adding of new products to our applications database? Let's explore how to create a post request that can leverage content negotiation to parse incoming request bodies. We want to support adding new items to our database through an additional endpoint. So we're going to add a post endpoint in our routing.kt file. Like with get requests there is a post method for configuring post requests. We'll call that method and we'll use a path of /add-product and once again, add our lambda so we can configure how to respond to these requests. Now we will expect a post body for this endpoint that includes an instance of the product that should be added. We can access a post body object using the call for that given request. So in this case, I'll create a variable to hold the parsed body and we can call, call.receive and pass in the type of…
Contents
-
-
-
-
-
-
-
(Locked)
Creating a new Ktor project6m 30s
-
(Locked)
Adding your first route5m 33s
-
(Locked)
Testing your local service6m 41s
-
(Locked)
Adding status pages7m 32s
-
(Locked)
Storing a list of products5m 42s
-
(Locked)
Returning typed responses11m 57s
-
(Locked)
Adding new products5m 38s
-
(Locked)
Authenticating routes7m 57s
-
(Locked)
Challenge: Return all active orders1m 35s
-
(Locked)
Solution: Return all active orders7m 4s
-
(Locked)
-