This tutorial shows you the operations to add a new clothing
resource as well as the operations to add that new item to an existing outfit.
This tutorial takes about 20 minutes to complete.
outfit
resource, ensure that the outfit
resource already exists in the service.Use the POST
method and a new clothing
resource to your service.
The
{base_url}
for the service ishttp://localhost:3000
.
To add a new clothing item:
If your local service is not running yet, start it with the following command:
cd <your-github-workspace>/coordinista-service/api
json-server -w coordinista-db.json
POST
/clothing
Content-Type: application/json
Accept: application/json
Add the properties of your new clothing item to the Request Body. For example:
[
{
"name": "silk skirt",
"type": "bottoms",
"color": "red",
"description": "mysterious",
"outfits": "cocktail party outfit"
}
]
Watch for the response body, which should generate your new clothing item with a unique id
.
[
{
"name": "silk skirt",
"type": "bottoms",
"color": "red",
"description": "mysterious",
"outfits": "cocktail party outfit",
"id": "d5dc"
}
]
You have successfully added a silk skirt to your clothing
resources.
To add a new clothing item to an outfit
resource:
PATCH
/outfits/{id}
Content-Type: application/json
Accept: application/json
Update the existing outfit’s clothingItem
parameters in the request body:
[
{
"clothingItems": ["little black dress, strappy heels, pendant necklace,silk skirt" ]
}
]
Remember to keep the existing
clothingItems
in your request.
outfits
resource with the new clothingItem
that you added.[
{
"name": "cocktail party outfit",
"season": "spring",
"event": "formal",
"description": "Something you can wear at a fancy work event and at the club.",
"clothingItems": [
"little black dress, strappy heels, pendant necklace,silk skirt"
],
"id": "5"
}
]
You have created a new clothing
resource, and added that clothing item to your outfit
resource.