Browse and test your LoopBack app's APIs
Go to file
Miroslav Bajtoš 1aaed162de
Merge pull request #240 from strongloop/update-lts-info
Update LTS information in README
2018-05-10 18:02:15 +02:00
.github Add stalebot configuration 2017-08-22 15:05:44 -04:00
example Add globalization 2016-08-04 00:47:24 -07:00
intl Update translated strings Q3 2017 2017-08-10 15:20:36 -04:00
lib update copyright notices and license 2016-05-05 17:10:55 -07:00
public Change Explorer header to use LoopBack 2017-03-24 10:24:06 +01:00
test [SEMVER-MAJOR] Remove deprecated CORS support 2018-04-17 15:47:29 +02:00
.eslintignore Add eslint infrastructure 2016-04-22 17:07:56 -04:00
.eslintrc Fix linting errors 2016-04-22 17:18:04 -04:00
.gitignore Add translated files 2016-09-27 16:23:28 -04:00
.travis.yml Enable Node.js 10 on Travis CI 2018-05-10 09:35:01 +02:00
CHANGES.md 6.0.0 2018-04-18 08:57:15 +02:00
CODEOWNERS CODEOWNERS: turn off PR notifications for STRML 2017-09-01 09:22:00 +02:00
CONTRIBUTING.md Update URLs in CONTRIBUTING.md (#169) 2016-07-13 17:40:35 -07:00
LICENSE chore: update license 2017-11-10 18:06:29 -05:00
README.md Update LTS information in README 2018-05-10 09:40:24 +02:00
index.js [SEMVER-MAJOR] Remove deprecated CORS support 2018-04-17 15:47:29 +02:00
package.json 6.0.0 2018-04-18 08:57:15 +02:00

README.md

loopback-component-explorer

Browse and test your LoopBack app's APIs.

Supported versions

Current Long Term Support Maintenance
6.x 5.x 4.x

Learn more about our LTS plan in docs.

Basic Usage

Below is a simple LoopBack application. The explorer is mounted at /explorer.

var loopback = require('loopback');
var app = loopback();
var explorer = require('../');
var port = 3000;

var Product = loopback.Model.extend('product');
Product.attachTo(loopback.memory());
app.model(Product);

app.use('/api', loopback.rest());

// Register explorer using component-centric API:
explorer(app, { basePath: '/api', mountPath: '/explorer' });
// Alternatively, register as a middleware:
app.use('/explorer', explorer.routes(app, { basePath: '/api' }));

console.log("Explorer mounted at localhost:" + port + "/explorer");

app.listen(port);

Upgrading from v1.x

To upgrade your application using loopback-explorer version 1.x, just replace explorer() with explorer.routes() in your server script:

var explorer = require('loopback-component-explorer');  // Module was loopback-explorer in v. 2.0.1 and earlier

// v1.x - does not work anymore
app.use('/explorer', explorer(app, options);
// v2.x
app.use('/explorer', explorer.routes(app, options));

In applications scaffolded by lb app, the idiomatic way is to register loopback-component-explorer in server/component-config.json:

{
  "loopback-component-explorer": {
    "mountPath": "/explorer"
  }
}

Advanced Usage

Many aspects of the explorer are configurable.

See options for a description of these options:

// Mount middleware before calling `explorer()` to add custom headers, auth, etc.
app.use('/explorer', loopback.basicAuth('user', 'password'));
explorer(app, {
  basePath: '/custom-api-root',
  uiDirs: [
    path.resolve(__dirname, 'public'),
    path.resolve(__dirname, 'node_modules', 'swagger-ui')
  ]
  apiInfo: {
    'title': 'My API',
    'description': 'Explorer example app.'
  },
  resourcePath: 'swagger.json',
  version: '0.1-unreleasable'
}));
app.use('/custom-api-root', loopback.rest());

In applications scaffolded by lb app, you can edit the server/component-config.json:

{
  "loopback-component-explorer": {
    "mountPath": "/explorer",
    "apiInfo": {
      "title": "My App",
      "description": "Description of my app APIs.",
      "termsOfServiceUrl": "http://api.mycompany.io/terms/",
      "contact": "apiteam@mycompany.io",
      "license": "Apache 2.0",
      "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.html"
    }
  }
}

Options

Options are passed to explorer(app, options).

basePath: String

Default: app.get('restAPIRoot') or '/api'.

Sets the API's base path. This must be set if you are mounting your api to a path different than '/api', e.g. with `loopback.use('/custom-api-root', loopback.rest());

mountPath: String

Default: /explorer

Set the path where to mount the explorer component.

protocol: String

Default: null

A hard override for the outgoing protocol (http or https) that is designated in Swagger resource documents. By default, loopback-component-explorer will write the protocol that was used to retrieve the doc. This option is useful if, for instance, your API sits behind an SSL terminator and thus needs to report its endpoints as https, even though incoming traffic is auto-detected as http.

uiDirs: Array of Strings

Sets a list of paths within your application for overriding Swagger UI files.

If present, will search uiDirs first when attempting to load Swagger UI, allowing you to pick and choose overrides to the interface. Use this to style your explorer or add additional functionality.

See index.html, where you may want to begin your overrides. The rest of the UI is provided by Swagger UI.

apiInfo: Object

Additional information about your API. See the spec.

resourcePath: String

Default: 'resources'

Sets a different path for the resource listing. You generally shouldn't have to change this.

version: String

Default: Read from package.json

Sets your API version. If not present, will read from your app's package.json.