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 - REST Tutorial
From the course: Building APIs with Swagger and the OpenAPI Specification
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Defining APIs3m 23s
-
Reading the specification5m 40s
-
Paths with query parameters3m 53s
-
Template parameters in paths4m 45s
-
Building posts with request bodies3m 34s
-
Achieving reusability with components7m 1s
-
Response objects3m 34s
-
Reusing parameters2m 41s
-
Content negotiation2m 21s
-
Swagger UI3m 22s
-
Challenge: Create company blog posts1m 9s
-
Solution: Create company blog posts3m 37s
-
-
-
-