4. Use the Swift API to manage containers and objects
In this section, you’ll run through some typical Swift API operations by using the Postman Chrome application.
- In Postman, click the + icon to open a new tab.
- Copy the
url
value that you saved in the previous section into the URL - Append
/mycontainer
to the URL. - Change the HTTP verb from GET to PUT to create a new container.
- Click Headers(0) and create a header with the label X-Auth-Token and value set to the value of the
X-Subject-Token
that you saved in the previous section.
- Click Send to verify that the returned Status is
201 Created
.
- Change the HTTP verb from PUT to HEAD to get the metadata for the new container. Then, click Note that you are reusing the same header value from the previous request.
- Verify that the returned Status is 204 No Content and that several metadata values are in the returned HTTP header.
- Change the HTTP verb from HEAD to PUT to do an upload operation.
- Click the Body tab and then select binary.
- Click Choose File and select a file on your local system.
- Go back to the URL field and append
/filename
to the URL wherefilename
is the name of the file that you selected. For example if you selectedfoo.txt
, then you append/foo.txt
to the URL.
- Click Send and verify that
Status 201 Created
is returned. - Change the HTTP verb from PUT to GET so that you can send a list request for the container.
- Remove the file name suffix from the URL.
- Click Send and verify that the name of the file that you just uploaded is returned.
- Append
?format=json
to the URL and send the GET request again. Verify that information about the file that you uploaded is returned in JSON format. - Remove the
?format=json
suffix from the URL and append/filename
to the URL wherefilename
is the name of the file that you uploaded earlier. - Click Send and verify that the content of the file is returned and that the status is
200 OK
.
- Optional: Before you remove the file and container, return to the Object Storage service management page and investigate the container and file that you added. Add more files or containers if you want.
- Change the HTTP verb from GET to DELETE to delete the file that you uploaded earlier.
- Click Send and verify that S
tatus 204 No content
is returned. - Change the HTTP verb from DELETE to GET so that you can send a list request for the container.
- Remove the file name suffix from the URL.
- Click Send and verify that
Status 204 No content
is returned. Note that there is no content because the container has no files.