Adding a Delete request to OAS
We continue with our musicAPI from the previous lab. The second request to define will delete a playlist using the DELETE method. Here is a sample request:
DELETE https://virtserver.swaggerhub.com/Orange-formation/musicAPI/1.0.0/playlist/playlist333
Under
paths, add the second path as shown below:
# Playlists
/playlist/{playlist-id}:
# Delete a playlist
delete:
# Path parameter
parameters:
# Playlist id
- name: playlist-id
in: path
required: true
type: string
# Incomplete response (to finish later)
responses:
# Response code
200:
description: Successful response
The code above does the following:
Add the path
/playlist/{playlist-id} as the next key. It’s the part of the
URL after the base path. It should start with a / and contain {playlist-id} to indicate a
path parameter.
Add the HTTP method Delete as the next key.
Add the parameters key.
Add the path parameter as a list item. You will need to have keys for name, in, required, and type. Don’t forget that you need a dash at the beginning because even though there’s only one parameter, it’s still considered a list item.
Finally, addd a basic response
Your
API documentation contains now a GET and a Delete. Try to invoke the delete method. What is the response code?
This won’t actually work because the
API is fictional and there is no resource to delete. But if it were real, then clicking that button would actually make a call to the
API and show you the results.
Back to top