From the course: Building APIs with Swagger and the OpenAPI Specification

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Content negotiation

Content negotiation - REST Tutorial

From the course: Building APIs with Swagger and the OpenAPI Specification

Start my 1-month free trial

Content negotiation

- [Instructor] In this lesson, we'll learn how to use content negotiation to define different response formats for API operations. Currently, we've defined all of our API responses in a JSON format. Sometimes you'll need to use other formats like xml. With the introduction of content negotiation in OAS 3.0, we have the ability to accept or provide multiple media types for our API operations. Let's leverage this new feature by providing an xml response from our product endpoint that uses a template parameter. You'll see how extremely simple this is once we work through our example. You'll notice that we have our product endpoint using the template parameter, and within this operation, we have defined our JSON response. All we need to do is specify a second media type, right in line with the first, and in this case, it's going to be application/xml. And then we just specify the schema object and we point to our reusable product component. And at this point if we take a look at our API…

Contents