Alright so now we've created our post function let's go ahead and test this in
the browser now the Django development server should automatically refresh when
you save the updates to the file so all we need to do is load up Google Chrome
and head over to the API view page
Alright so this is the hello API view
from the previous time we tested it since we've made a change let's refresh
the page and you can see that this name field appears here at the bottom of the
page this appears because we've added a serializer class to our function or to
our API view as well as the post function so the Django rest framework
browsable API knows that we're expecting an input with a name field so that's why
it's created this handy name input here that we can use to test our API
okay so let's type our name here in the input and then click on post you can see
that when you did that it passed the request to our API view to the post
function because we made a HTTP POST request then it passed the data that we
provided which was an object with the name field into the data it validated it
and it passed the validation so it returned a response of a message with
hello and the name input that we gave okay so we can see that the request
works on a valid request now let's try an invalid one so we can do that by
typing the same name but let's put lots of exclamation marks here to exceed the
10 character limit and hit post and you can see that we got a handy response
with a HTTP 400 describing that the field must be no longer than 10
characters long
If we had extra fields that were invalid then the Django rest
framework would return the validation errors for all of the fields that we
provided in the request which is really handy because then in the client
application you can pass this into the form input and display these errors in
line in the form for the user to see
Okay so that's how you add a post
function to an API view