From the course: Building APIs with Swagger and the OpenAPI Specification
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Reusing parameters - REST Tutorial
From the course: Building APIs with Swagger and the OpenAPI Specification
Reusing parameters
- [Instructor] Query parameters are another object that can be reused in API definition files. If we take a look at our API definition, we'll see, within our product endpoint, that we have the paging parameters that we established for the get operation. These parameters could easily be reused for other endpoints that require paging. So let's go ahead and copy these, because we're going to move them within the component section to make them reusable. To do that, we simply add the parameters object to the component section, and then we need to provide a name for each of the parameters that we want to define. So, in this case, I'm going to supply a parameter named pageNumber, and then we're going to grab the YAML that defines these parameters and paste it in, and then we simply adjust the indentation to conform to YAML standards. And then we'll need to build out our second parameter, which is going to be the pageSize, and here we'll, once again, need to do some indentation. And once…
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
-
-
-
-
(Locked)
Defining APIs3m 23s
-
(Locked)
Reading the specification5m 40s
-
(Locked)
Paths with query parameters3m 53s
-
(Locked)
Template parameters in paths4m 45s
-
(Locked)
Building posts with request bodies3m 34s
-
(Locked)
Achieving reusability with components7m 1s
-
(Locked)
Response objects3m 34s
-
(Locked)
Reusing parameters2m 41s
-
(Locked)
Content negotiation2m 21s
-
(Locked)
Swagger UI3m 22s
-
(Locked)
Challenge: Create company blog posts1m 9s
-
(Locked)
Solution: Create company blog posts3m 37s
-
(Locked)
-
-
-