Let's test our put patch and delete methods in the browser make sure that
the development server is running and that it is refreshed with the latest
changes if it hasn't refreshed then push ctrl C to stop the server and then
restart it
Then load up Chrome and head over to our URL here so 127.0.0.1 :
8000 forward slash api forward slash hello view
and then you may need to update the page to
see the latest changes which is the put and patch forms you can see that there has
been a few more options added to this page previously we only had this post
option with the name now we also have this second option down here which has a
HTML form with put and then you can also see that the delete option has been
added because we added these functions to our API view the Django rest
framework knows to render these options in the browsable api for us to test so
if we click the delete option it'll prompt us are we sure you wish to delete
this hello API and hit delete and you can see that we got the delete response
that we defined in our delete function here which is method delete now let's
test the put option now put as I mentioned in the previous video is for
updating the entire object so you have to provide all of the fields required so
if we put name mark and then hit put you can see that we get the response for our
HTTP put function which is to respond a method and put ok to access the patch
method you need to click on the raw data tab that is added to our browsable
API
The reason you need to use raw data is because the way patch works is you
provide only the fields that you want to update in the API so if you
use this HTML form then it basically has a list of all the fields that are
available and when you put put it would put the contents of all of
these fields to the API whereas with patch you want to actually
exclude fields so the Django rest framework requires that you define the
content as a JSON string here in the editor
So if we just do open and close a
blank JSON string and hit patch this will do a patch request and return the
response from our patch function so that's how all the different HTTP
methods work with an API view now that we've added these to our API let's go
ahead and commit our changes and push it to github
So load up the terminal or the
git bash window open a new window which is on our profiles REST API project and
then type git add dot and git commit - m and we'll write the message added post
put patch and delete methods to our API view
Hit enter and then do git push
origin to push these changes to github.