Lab02 http response dto
Create a response object to hold information to be returned.
A. Create DTO¶
-
Create a new class,
CoffeeOrderResponse
-
Add 2 member variables:
- A
String
namedid
- A
String
namedprice
- A
-
Use IntelliJ to generate the getters and setters (CMD + N)
B. Return DTO¶
-
Open up the
CoffeeOrderApiController
and change thecoffeeOrderInfo
method to return aCoffeeOrderResponse
instead of the existingString
-
Inside the method, create a coffee order:
- Create a new
CoffeeOrder
- Set the size to
SMALL
- Create a new
-
Create a response from the order:
- Instantiate a
CoffeeOrderResponse
- Set the response's ID to the incoming ID
- Set the response's Price to the price from the
CoffeeOrder
- Instantiate a
-
Return the
CoffeeOrderResponse
C. Try It Out¶
-
Run the
CoffeeVendingMachineApplication
from within IntelliJ IDEA. -
Make a request against the endpoint by opening the URL:
http://localhost:8080/api/coffeeorders/123
-
You should get something like:
{"id": "123", "price": "100"}