Code Monkey home page Code Monkey logo

api-explorer's Introduction

API Explorer js-standard-style Circle CI

API Explorer is a live documentation client for HTTP APIs that provides a nice and highly customizable UI.

  • Extensible: API Explorer provides an extensible system, based on plugins, that allow you to control several aspects of the UI, interactions with your API endpoints and the API Specification.
  • API Specification loaders: It is pre-bundled with Swagger (v1, v2) API specification loaded, but can be extended to handle other specifications.
  • Multiple APIs: You can have multiple API handled in the same UI for convenience.
  • Developer friendly: We provide a built-in development server to test your plugins and settings, with features such as a proxy for bypass CORS restrictions
  • Clean UI and user friendly: The UI is focused in the API operation, making it a first class citizen in the UI. Some user friendly aspects are also implemented, like: deep-link to api operations with pre-filled parameters; history for API request responses; API deprecation indicator; custom headers.

How To Use

Since API Explorer is distributed as a library it won't work out of the box without some configuration. You can opt-in for the following minimum configuration or use an advanced configuration explained in the advanced configuration section.

These are the steps to get API Explorer working for some API that is described in Swagger v2.

  • Download the API.Explorer.*.zip file from the releases page for this project.
  • Expand the file to get the APIExplorer.umd.js and index.html files
    • The .js file is the API Explorer library bundle
    • The index.html is a sample HTML index file you can/should use to bootstrap. It contains some CSS/JS external of API Explorer, the DOM hook node and some styles.
  • Copy the files to a new folder or to the root of your Server/API
  • Edit the index.html file to configure your API
    • Add a <script ...> tag as the last <body> element with the following:

    • Option A) if you are hosting index.html in the same server/api:

      APIExplorer
        .addAPI('some-api', 'swagger2', '/path/to/the/api/spec', c => {
          c.addHeader('X-API-Key', 'Some Value')  // You may add custom headers
        })
        .start()
    • Option B) if you are hosting index.html in a distinct server/api:

      APIExplorer
        .addAPI('some-api', 'swagger2', 'https://example.com/path/to/the/api/spec', c => {
          c.addHeader('X-API-Key', 'Some Value')  // You may add custom headers
        })
        .configCORS({ credentials: 'omit' })
        .start()

Development

  • To build this project you need to clone the repository and do the following. Note that you can change the port number using the PORT environment variable.
$ npm install -D
$ cd packages/api-explorer
$ npm run demo
open http://localhost:3000
  • This project uses StandardJS for linting the code.
npm run lint
  • To generate a production build you need to run the following commands:
yarn install
yarn run build

The output files are stored in the dist folder. You can grab the files and place then in your application server.

You can also use a local server to run this application using npm start

Advanced Configuration

APIExplorer uses a fluent API to specify the internal behaviour. The following example configures two distinct APIs in the same API Explorer instance, with a custom widget HATEOAS, and a plugin samplePlugin. It also configure how to handle credentials in a CORS scenario. At the bottom, the start method triggers the API Specification download and subsequent UI render.

APIExplorer
  .addAPI('petstore', 'swagger2', 'https://api.swaggerhub.com/apis/anil614sagar/petStore/1.0.0', c => {
    c.addHeader('X-Foo', 'Some Value')
    c.addHeader('X-Bar', 'Another Value')
    c.useProxy(true)
    c.setRequestTimeoutInMiliseconds(5000)
    c.listOperationsAtWelcome(true)
  })
  .addAPI('github', 'swagger2', 'https://api.apis.guru/v2/specs/github.com/v3/swagger.json', c => {
    c.useProxy(true)
  })
  .addWidgetTab('HATEOAS', APIExplorer.HATEOASWidget)
  .addPlugin(samplePlugin)
  .configCORS({ credentials: 'omit' })
  .start()

Core Maintainers

Contributing

We appreciate any contribution to API Explorer, please check out CONTRIBUTING.md. We keep a list of features and bugs in the issue tracker.

Contributors

You can check all the contributors of this project here. A special thanks to:

Publishing

npm version <update_type>

where update_type is minor, major or build.

Circle CI will then publish the new version to NPM triggered by a new tag that is pushed to git.

Try out

You can try the application in the online development sandbox that is using the Swagger PetStore API.

https://apiexplorer-app.herokuapp.com

Sample API Explorer

api-explorer's People

Contributors

cguedes avatar danielbcorreia avatar danielmalmeida avatar dependabot-preview[bot] avatar dependabot[bot] avatar diogommsilva avatar marcosandre avatar miguelnv avatar not-allowed avatar nunoas avatar pedromss avatar pmhsfelix avatar tiagomrsousa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

api-explorer's Issues

Allow .configPlugins() to be optional

This method creates the APIExplorer.plugins prop. If we miss this .configPlugins() call the prop is undefined.

Set default value in APIExplorer constructor or elsewhere. ;-)

Swagger Spec in the url

The idea is to load a diferent spec. We can use a url in the query string or a settings page to add new apis to the current app (of course this will not be persisted in any way)

In a first phase we could make only the query string aproach

Fix tests

Tests are failing because global APIExplorer requirement for plugin reducers.

Change the register of samples to a more automatic way

The register of samples is very explicit because we are defining the paths of the where to read the samples from.

We should read the sample directories and, by convention, call the api.js file and register the endpoints of the samples.

recursive(__dirname + '/sampleapp', function (err, files) { var apiFiles = Enumerable.from(files).where(f => f.indexOf('api.js') > 1).toArray() for(i in apiFiles){ console.log(apiFiles[i]) var api = require(apiFiles[i]) api(app,basePath) } })

see server.js

Create a more complex sample (multiple APIs, plugins, etc)

We should create a more complex sample in order to test other functionalities of API explorer.
Petshop should remain a very basic example (hello world style) and this new sample should be richer in features.

Some goals:

  • Multiple APIs
  • Samples for all plugin types
  • Several (advanced) configuration samples

A pre-requirement of this is to get hold of some swagger samples that align with our target license.

Change APIExplore.config to APIExplorer.configApiSpec

This will better express the intent of this configuration element in the APIExplorer configuration API.

APIExplorer
  .config(c => {
    c.swagger2API('petstore', 'http://localhost:3000/samples/petstore.json', true)
  })

Fetching a Swagger specification over HTTP is being blocked

Fetching resources, more specifically, swagger specifications over HTTP is causing an error related with Mixed Content rule. This rule states that websites over HTTPS should not request content over an insure protocol such as HTTP, due to the vulnerabilities that such act may led.

Sample error using Pet Store over HTTP:

Mixed Content: The page at 'https://apiexplorer-app.herokuapp.com/?swaggerSpec=http%3A%2F%2Fpetstore.sw…waggerLoader=swagger1API&swaggerUseProxy=true&swaggerLoader=Swagger2Loader' was loaded over HTTPS, but requested an insecure resource 'http://petstore.swagger.io/v2/swagger.json'. This request has been blocked; the content must be served over HTTPS.

Reproducing this error:

We should discuss what should be the behaviour of the UI when faced with such scenario.

For requests to spec's being server HTTP, I think the check "use proxy because of CORS" should be checked and grayed out. Since in this case we want always to bypass the validation in the server side, and also make sure the received content is in fact what we expect to receive, i.e, a proper swagger specification.

Remove support for url spec in querystring

When passing a swagger specification to the API Explorer the preceding request URI is malformed.

Reproducing this scenario:

  • browser: chrome
  • swagger spec: petstore
  • version: 2
  • use proxy: yes

Output URI

https://apiexplorer-app.herokuapp.com/?swaggerSpec=http%3A%2F%2Fpetstore.swagger.io%2Fv2%2Fswagger.json&swaggerLoader%5B%5D=swagger1API&swaggerLoader%5B%5D=Swagger2Loader&swaggerUseProxy%5B%5D=true&swaggerUseProxy%5B%5D=on

As we can see the swaggerSpec parameter contains the encoded URI bellow:

http%3A%2F%2Fpetstore.swagger.io%2Fv2%2Fswagger.json&swaggerLoader%5B%5D=swagger1API&swaggerLoader%5B%5D=Swagger2Loader&swaggerUseProxy%5B%5D=true&swaggerUseProxy%5B%5D=on

If we decode this URI we will get:

http://petstore.swagger.io/v2/swagger.json&swaggerLoader[]=swagger1API&swaggerLoader[]=Swagger2Loader&swaggerUseProxy[]=true&swaggerUseProxy[]=on

The parameters &swaggerUseProxy[]=on and swaggerLoader[]=swagger1API should not being sent, and also the construct above [URI][&param=value&param=value] is invalid according to the URI RFC specification querystring part is not being preceded by an question mark (?).

On the screenshot of the API Explorer README containing the use case GIF, we can see that this bug was already present by then:

screen shot 2015-12-11 at 21 06 27

We should be using import for fetching images inside Components

When using images in our components, we should call require to include those images. That will enable Webpack to export them as dependencies automatically, making the code cleaner.

So instead of this:

<img src='data:image/png;base64,iVBOR....' />

We will have something like this:

<img src={ import `${ASSETS_DIR}/my-image.png` />

Split the operations ui into components

The idea is to split the Try out, spec and Response Schema into different components, maintaining the current logic.

In the context of this issue we should also give support for the additions of new operations

Improvements

  • Add default accepts to the Executer
  • Preserve the original query string in all the requests
  • Add color change according to the result of the request
  • Add request and response headers to the Try out view

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.