WEBVTT
Kind: captions
Language: en

00:00:00.030 --> 00:00:05.790
Alright so now we've created our post
function let's go ahead and test this in

00:00:05.790 --> 00:00:13.080
the browser now the Django development
server should automatically refresh when

00:00:13.080 --> 00:00:17.670
you save the updates to the file so all
we need to do is load up Google Chrome

00:00:17.670 --> 00:00:21.720
and head over to the API view page

00:00:21.720 --> 00:00:24.810
Alright so this is the hello API view

00:00:24.810 --> 00:00:29.039
from the previous time we tested it
since we've made a change let's refresh

00:00:29.039 --> 00:00:34.230
the page and you can see that this name
field appears here at the bottom of the

00:00:34.230 --> 00:00:40.440
page this appears because we've added a
serializer class to our function or to

00:00:40.440 --> 00:00:44.660
our API view as well as the post
function so the Django rest framework

00:00:44.660 --> 00:00:52.199
browsable API knows that we're expecting
an input with a name field so that's why

00:00:52.199 --> 00:00:58.010
it's created this handy name input here
that we can use to test our API

00:00:58.010 --> 00:01:05.309
okay so let's type our name here in the
input and then click on post you can see

00:01:05.309 --> 00:01:10.950
that when you did that it passed the
request to our API view to the post

00:01:10.950 --> 00:01:16.320
function because we made a HTTP POST
request then it passed the data that we

00:01:16.320 --> 00:01:22.890
provided which was an object with the
name field into the data it validated it

00:01:22.890 --> 00:01:29.189
and it passed the validation so it
returned a response of a message with

00:01:29.189 --> 00:01:35.880
hello and the name input that we gave
okay so we can see that the request

00:01:35.880 --> 00:01:41.520
works on a valid request now let's try
an invalid one so we can do that by

00:01:41.520 --> 00:01:47.070
typing the same name but let's put lots
of exclamation marks here to exceed the

00:01:47.070 --> 00:01:53.189
10 character limit and hit post and you
can see that we got a handy response

00:01:53.189 --> 00:01:59.479
with a HTTP 400 describing that the
field must be no longer than 10

00:01:59.479 --> 00:02:02.580
characters long

00:02:02.580 --> 00:02:05.520
If we had extra fields
that were invalid then the Django rest

00:02:05.520 --> 00:02:09.149
framework would return the validation
errors for all of the fields that we

00:02:09.149 --> 00:02:12.840
provided in the request which is really
handy because then in the client

00:02:12.840 --> 00:02:19.379
application you can pass this into the
form input and display these errors in

00:02:19.379 --> 00:02:22.680
line in the form for the user to see

00:02:22.680 --> 00:02:25.110
Okay so that's how you add a post

00:02:25.110 --> 00:02:29.330
function to an API view

