An API Console as a standalone application
An API console for RAML (Restful Api Modeling Language) documents. The RAML Console allows browsing of API documentation and in-browser testing of API methods.
Unlike the api-console
element, this application can accept the URL query
parameter (api
) which points to the RAML file hosted on a remote machine.
The application will download the RAML file and it's dependencies and then it will run RAML to JavaScript parser and raml JavaScript enhancer.
When this task are performed the documentation will be displayed as in the
api-console
element.
The API Console can be used either as a HTML element (Web Components) or as a standalone application.
To use the API console as a HTML element refer to the api-console element repository for detailed usage.
Otherwise use following directions.
To run the console, you'll need the following:
git clone https://github.com/advanced-rest-client/api-console-app.git
cd api-console-app
npm install && bower install
polymer
tools
npm install -g polymer-cli
polymer build
This will generate two versions of the API Console application. Both in the build/
directory.
The API console contains two fragments. One - main - is the critical resources: the parser, RAML JavaScript enhancer and the documentation viewer. Second fragment is the HTTP request and response panels that will be downloaded when the user request them for the first time.
To test the app locally user polymer
tools to run dev server:
polymer serve --open -p 8080
When the website opens, add the api
query parameter that points to the RAML
file.
http://localhost:8080/?api=https://cdn.rawgit.com/advanced-rest-client/drive-raml-api-v2/ab60ed28/api.raml
The application supports deep linking. It means that you can link to the documentation to specific resource / method / type documentation.
To build an URL to a specific fragment of the documentation you have to add a JSON path to the resource you want to link to. JSON path is a string representing a path to the object. For example if you want to link to the first method in the first resource in the RAML structure the path will look like the following:
resources.0.methods.0
Because some servers don't like dots ('.') in the path the app uses dashes instead of dots:
resources-0-methods-0
Now, to apply it to the URL you have to add it to the URL path segment, after the /docs
path prefix. The final URL will be:
http://localhost:8080/docs/resources-0-methods-0
This URL will always point to the first method in the first resource in the RAML structure.
To better understand paths consider following RAML example
#%RAML 1.0
title: Google Drive
types:
type1: ...
type2: ...
documentation:
- title: Doc
content: Documentation
/files:
post: ...
get: ...
/{fileId}:
path: ...
get: ...
/apps:
post: ...
get: ...
It is a default URL after loading the RAML and if the path is not set. It displays summary information about the RAML docuemnt.
Links to the resource summary documentation. You have to add a resource index in the RAML structure according to regexp:
(resource-(\d+)-?)+
Examples:
resources-1
- second resource in the RAML structure, the /apps
in exampleresources-0-resources-0
- First sub-resource of the first resource, the /files/{fileId}
in the exampleLinks to the method documentation.
(resource-(\d+)-?)-(method(\d+)-?)
Examples:
resources-0-resources-0-methods-0
- First method in the first sub-resource of the first resource, the PATCH /files/{fileId}
in the exampleresources-1-methods-1
- Second method of the second resource, the GET /apps
in the exampleLinks to the type documentation.
type-(\d+)
Examples:
types-0
- First type in RAML structure, the type1
in the exampletypes-1
- Second type in RAML structure, the type2
in the exampleLinks to the documentation object in the RAML structure
documentation-(\d+)
Examples:
documentation-0
- First element in the documentation list, the Doc
documentation in the example.api
parameterThe URL to the RAML file.
Other parameters might be available in the future.