-
Notifications
You must be signed in to change notification settings - Fork 10
Implementing the Swagger API Specification
To be compliant with the DTS Swagger API Specification, your implementation must:
- Serve the swagger.json specification
- Answer at the paths identified by combining the
host
,schemes
,basePath
with individual paths defined in thepaths
property of the specification. a. This includes the parameters listed for each request. - Return responses which adhere in both structure and HTTP response code value to those defined in the specification for each path. In addition the, HTTP content-type headers returned by your server at those addresses must adhere to the values listed in the
produces
property of the spec.
-
Publish a route which returns the specification JSON document.
e.g. http://example.org/api/apidocs
It can be a good idea to allow room for a version identifier in that route, in case a new version of the specification is published.
-
Before serving it, you must change the values in the specification JSON document which are specific to the deployment:
"host": "<your hostname>",
host
should be set to the hostname of your service. It should not include the scheme (i.e. http or https)
"schemes": [<https|http>],
schemes
should be set to a list of the schemes you serve the API at, in order of preference. If you don't have an SSL certificate for your server, then the value for schemes
should just be ["http"]
. If you do have an SSL certificate, then it's preferred to list that first: ["https","http"]
.
"basePath": "<path prefix for api requests>",
basePath
should be set to the root path prefix, if any, that you serve the API requests at.
Client applications will expect to form requests to your API endpoint by combining the schemes
, host
and basePath
values, and then access the paths advertised in the rest of the specification at that location.
So, for example, with the the following values...
"host": "example.org",
"schemes": ["https"],
"basePath": "api/v1.0.0",
...clients to your API should be able to expect to make calls to the following addresses:
https://example.org/api/v1.0.0/collections
https://example.org/api/v1.0.0/collections/{id}
https://example.org/api/v1.0.0/collections/{id}/capabilities
https://example.org/api/v1.0.0/collections/{id}/metadata
Everything from /collections
on in the path of the request should be standard across ALL implementations of the API. These paths are defined in the paths
property of the specification JSON document.
The combination of the host
,schemes
and basePath
values are specific to individual implementations.
If your service requires authentication, this information can also be expressed via the specification. For more information on the above points and instructions on implementation authentication protocols, see the Swagger Specification
Once you have completed the above steps, you should be able to test your API using the Swagger-UI that is deployed in the Distributed Text Services GitHub Pages at https://distributed-text-services.github.io/collection-api/
-
Enter the url at which you serve the swagger specification in the input box at the top of the UI and click Explore.
-
You should see the Collections topic and be able to click Expand Operations to see the list of all the available operations.
-
Use the Try it Out! Buttons for each operation to test the request/response to your API.