HTTP Headers: Accept and Content Type

A free video tutorial from Sergey Kargopolov
Software developer
Rating: 4.6 out of 5Instructor rating
9 courses
141,833 students
HTTP Headers: Accept and Content Type

Lecture description

In this video we will learn about Accept and Content type HTTP headers and how they used with RESTful Web Services. 

Learn more from the full course

RESTful Web Service with Java JAX-RS. Create & Deploy to AWS

* Create REST API with JAX-RS and Jersey * Build Restful Web Service * Deploy to AWS * Implement CRUD with Hibernate *

09:17:43 of on-demand video • Updated November 2018

Install Java, Netbeans IDE, Postman, MySQL Service and Apache Tomcat on local Mac computer
Learn to send HTTP Requests with Postman client
Use Netbeans to write Java code
Create Java Project with Maven
Configure Hibernate framework to persist Java objects in MySQL database
Build RESTful Java Web Services with JAX-RS and Jersey framework
Startup AWS EC2 Linux Server in Amazon Cloud
Configure AWS EC2 Instance Firewall
Connect to AWS EC2 Instance via SSH
Create MySQL database and users
Install MySQL Server and Apache Tomcat on AWS EC2 Linux Server
Deploy RESTful Java Web Service to a remote AWS EC2 Linux Server
Implement Email Verification with AWS SES(Simple Email Service)
English [Auto]
When we send the request to create a user profile, for example, the user details that are being sent are included and request body and this information about the user profile is well structured in the adjacent format. So when silverside script receives this information, it should be able to take this adjacent text and convert it into a Java object and for a service script to be able to convert this text into a Java object. It needs to know how to convert or it needs to know what type of content. There's actually bequest. Carie's in its body. Is it XML format or is it Chazen format or is it some other format is plain text. So additionally, the structuring the user details and adjacent format we need to tell or we need to include into HDP request the details about the type of the content. It is scary. And to do that we can use content type HTP header and we have a top headers where we can list all the headers that we need in this HTP request. And the first one is called content type. So if I start typing here application, I can see all the different content types that HDB header can carry and the one that we need is application. Jason, our application forward slash Jason application Jason because our body is in JSON format. OK, so when suicide web service responds back to our request, it can also send us some additional information, like, for example, the user profile details or a list of all users if we send the request to get a list of all users. And this information can also be structured in a different format. For example, it can be Jason or it can be XML. So to tell silverside which content type we expect back and we can accept we use a different they should be header and it's called accept and they will also provide application Jassam as the content type that we can accept. So let me now send this EDP request, which is going to use HTTP meant that post and then it will be sent to an endpoint. API users is a collection of users and because it is an issue, people request a script that creates and user profile will be triggered and it will accept this Jaeson document as a material to create the new user profile. So let's send it and we get back a successful response, which is also in JSON format. So let me go to headers now and let me change the accept HDB had there from Jaeson to XML, which will tell our Web service that we accept back application XML rather than Jason. So let me send it now and I get back a response which contains user details and some additional information like separation and the status of the response. But this information is structured in XML. Now, this conversion from Jason to Java Objects and from Java Object into XML format takes place for us at the magically. But unless we configure our Web series to support one of these formats or both of these formats, this conversion will not take place. And in fact, if we attempt to send data in a format which are Web services, does not support or return data in a format that is not supported by sender, application and error will take place and a request of the operation might not even be completed successfully. So keep in mind this to which beheaders and in my following videos, I will show you how to configure a Web service to support each of these formats.