WEBVTT
Kind: captions
Language: en

00:00:00.030 --> 00:00:06.930
Let's test our put patch and delete
methods in the browser make sure that

00:00:06.930 --> 00:00:10.290
the development server is running and
that it is refreshed with the latest

00:00:10.290 --> 00:00:14.610
changes if it hasn't refreshed then push
ctrl C to stop the server and then

00:00:14.610 --> 00:00:17.000
restart it

00:00:17.000 --> 00:00:24.000
Then load up Chrome and head
over to our URL here so 127.0.0.1 :

00:00:24.000 --> 00:00:28.580
8000 forward slash api forward slash hello view

00:00:28.580 --> 00:00:31.289
and then you may need to update the page to

00:00:31.289 --> 00:00:36.030
see the latest changes which is the put and patch forms you can see that there has

00:00:36.030 --> 00:00:41.730
been a few more options added to this
page previously we only had this post

00:00:41.730 --> 00:00:46.980
option with the name now we also have
this second option down here which has a

00:00:46.980 --> 00:00:51.510
HTML form with put and then you can also
see that the delete option has been

00:00:51.510 --> 00:00:56.730
added because we added these functions
to our API view the Django rest

00:00:56.730 --> 00:01:03.270
framework knows to render these options
in the browsable api for us to test so

00:01:03.270 --> 00:01:07.530
if we click the delete option it'll
prompt us are we sure you wish to delete

00:01:07.530 --> 00:01:12.840
this hello API and hit delete and you
can see that we got the delete response

00:01:12.840 --> 00:01:20.430
that we defined in our delete function
here which is method delete now let's

00:01:20.430 --> 00:01:26.250
test the put option now put as I
mentioned in the previous video is for

00:01:26.250 --> 00:01:31.770
updating the entire object so you have
to provide all of the fields required so

00:01:31.770 --> 00:01:38.430
if we put name mark and then hit put you
can see that we get the response for our

00:01:38.430 --> 00:01:46.590
HTTP put function which is to respond a
method and put ok to access the patch

00:01:46.590 --> 00:01:53.130
method you need to click on the raw data
tab that is added to our browsable

00:01:53.130 --> 00:01:54.560
API

00:01:54.560 --> 00:02:00.360
The reason you need to use raw data
is because the way patch works is you

00:02:00.360 --> 00:02:06.420
provide only the fields that you want to update in the API so if you

00:02:06.420 --> 00:02:11.400
use this HTML form then it basically has
a list of all the fields that are

00:02:11.400 --> 00:02:16.560
available and when you put put it would put the contents of all of

00:02:16.560 --> 00:02:19.770
these fields to the API
whereas with patch you want to actually

00:02:19.770 --> 00:02:24.510
exclude fields so the Django rest
framework requires that you define the

00:02:24.510 --> 00:02:29.080
content as a JSON string here in the
editor

00:02:29.080 --> 00:02:31.470
So if we just do open and close a

00:02:31.470 --> 00:02:37.650
blank JSON string and hit patch this
will do a patch request and return the

00:02:37.650 --> 00:02:44.099
response from our patch function so
that's how all the different HTTP

00:02:44.099 --> 00:02:48.780
methods work with an API view now that
we've added these to our API let's go

00:02:48.780 --> 00:02:52.500
ahead and commit our changes and push it
to github

00:02:52.500 --> 00:02:54.090
So load up the terminal or the

00:02:54.090 --> 00:03:01.170
git bash window open a new window which
is on our profiles REST API project and

00:03:01.170 --> 00:03:11.060
then type git add dot and git commit - m
and we'll write the message added post

00:03:11.060 --> 00:03:21.420
put patch and delete methods to our API
view

00:03:21.420 --> 00:03:24.150
Hit enter and then do git push

00:03:24.150 --> 00:03:29.600
origin to push these changes to github.

