API Paths section
The second main part of the API definition is the Paths object. The Paths object defines all the relative paths to all Endpoints and their operations that this API offers.
Here is an example of the Paths object containing one path definition and one GET operation for the path:
paths: /now: get: parameters: - name: format in: query description: Format for returned date and/or time required: true schema: type: string responses: '200': description: ok content: application/text: schema: type: string
Object / Item | Description |
paths: | The Paths Object holds the relative paths to the individual Endpoints and their operations. The path is appended to the URL from the Server Object (described in the API Header section) to construct the full URL.ull URL. |
/now: | This is a Path Item Object that describes the operations available on a single path. If you want to use path parameters, you need to define them here.
Please refer to the Path Item Object documentation. |
get: | This is the Operation Object that describes a single API operation on a path. Under one Path Item Object, there can be one or many Operation Objects.
Please refer to the Reference documentation for Operation Object documentation. |
parameters: - name: format in: query description: Format for returned date and/or time required: true schema: type: string | Use the parameters section if you want to use parameters. You can define one or many parameters for API operation. Each parameter object includes the following fields:
Please refer to the Parameter Object documentation. |
responses: '200': description: ok content: application/text: schema: type: string | The Responses Object documents and defines the possible HTTP response codes of the API operation. It is not necessary to cover all the possible response codes, but it is good practice to cover all successful responses and any known errors. |
When defining REST APIs with OpenAPI Specification, it is recommended to follow common guidelines for REST Status Codes. For details, please read, for example, "The Complete Guide to Status Codes for Meaningful REST APIs.
The next article is Introduction to API Authentication